我在学习NodeJS,并且遇到很大问题。脚本nodeJS出现此错误
使用ES6和执行与node --harmony
在我的构造this
告诉我它Magic {}
而bar()
它从我的功能。
我到处寻找,但我没有找到如何解决它。
#!/usr/local/bin/node --harmony
class Test {
constructor() {
var tab = []
tab.push(this.bar)
console.log(this) // Magic {}
tab[0]("hello")
// this.bar("world")
}
foo(str) {
return str
}
bar(str) {
console.log(this.foo(str)) // TypeError: this.foo is not a function
console.log(this) // [ [Function: bar] ]
}
}
new Test()