如何解决TypeScript:将参数传递给回调函数
以下代码来自azure-account
VSCode扩展的代码示例的源代码。
export function activate(context: ExtensionContext) {
const azureAccount = extensions.getExtension<AzureAccount>('ms-vscode.azure-account')!.exports;
const subscriptions = context.subscriptions;
subscriptions.push(commands.registerCommand('azure-account-sample.showSubscriptions',showSubscriptions(azureAccount)));
subscriptions.push(commands.registerCommand('azure-account-sample.showAppServices',showAppServices(azureAccount)));
}
如您所见,代码定义了两个命令,这意味着当用户使用命令azure-account-sample.showSubscription
时,它将调用函数showSubscriptions(azureAccount)
。
但是azureAccount
对象如何通过这种方式传递呢?在我看来,代码应这样写:
commands.registerCommand('azure-account-sample.showSubscriptions',showSubscriptions,azureAccount);
//commands.registerCommand
function registerCommand(callback,...args){
callback(args);
}
//defination of registerCommand from the source code of vscode api
export function registerCommand(command: string,callback: (...args: any[]) => any,thisArg?: any): Disposable;
解决方法
SmallLibs = $($(SmallLibSrc:%.cxx=lib%.a):%.c=lib%.a) $($(SmallLibSrc:%.cxx=lib%.so):%.c=lib%.so)
返回另一个函数,它是实际的回调
showSubscriptions
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。