VS代码Intellisense带有ES6模块



当模块方法是这样实例化时,是否有一种方法可以使VS代码IntelliSense起作用:

lib.js:

export function foo() {
    this.aMethod = function() {
        console.log('bar');
    }
}

main.js:

import { foo } from "./lib.js";
function bar() {
    this.newFoo = new foo();
    this.newFoo.  <-- no intellisense here, "aMethod" is not suggested...
}

我做错了什么?

定义类的正确方法是通过做

export function foo() {
    this.aMethod = function() {
        console.log('bar');
    }
}

export function foo() {
}
foo.prototype.aMethod = function() {
    console.log('bar');
}

vscode应该能够在

之后检测对象的方法

最新更新