在javascript中有一些我不理解的东西,并将一个示例问题分解为一个基本案例:
a = function () {
this.b = 5;
}
a.prototype.c = function () {
alert(this.b);
}
var d = new a();
var e = d.c; // how do I save a ref to the method including the context (object)??
d.c(); // 5 -> ok
e(); // undefined -> wtf??
Run Code Online (Sandbox Code Playgroud)
那么为什么在上一个例子中没有上下文的情况下调用函数呢?我如何用上下文调用它?
提前致谢 :-)
javascript ×1