【发布时间】:2020-08-20 06:49:24
【问题描述】:
以下代码来自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;
【问题讨论】:
标签: typescript arguments vscode-extensions