我在nodejs中运行以下代码
this.x = 'global x';
class Point {
constructor(x) {
this.x = x;
}
toString() {
return this.x;
}
}
var obj = new Point(1);
obj.toString();// 1 as expected
var a = obj.toString;// Here I can do something like var a = obj.toString.bind(obj); to get rid of the situation. But I am curious to know how can we write `var self = this`;
a();// TypeError: Cannot read property 'x' of undefined
Run Code Online (Sandbox Code Playgroud)
a();抛出错误.
我们怎样才能像var self = this;过去那样做es5 …
随着节点v4.0.0的发布.这个节点的版本弃用许多功能,如util.isArray,util.isRegEx,UTIL.isDate,util.isBoolean等等.
我想知道为什么这发生在节点上?
在ES6中是否有这些东西的原生支持?
或者节点是否提供了更好的解决方案而不是这些东西?