关于this的最终回复,参见ECMA-262 10.2.3: The caller provides the this value. If the this value provided by the caller is not an object (including the case where it is null), then the this value is the global object. 其他的参见Javascript Scope Chain相关资料。
var B={m:5}; function A(){} A.prototype=B; A.prototype.z=8; b=new A(); alert(b.z); //output 8 alert(b.m); //output 5 alert(B.z); //output 8 for(S in B) document.write(S+"="+B[S])//m=5z=8
The caller provides the this value. If the this value provided by the caller is not an object (including the case where it is null), then the this value is the global object.
其他的参见Javascript Scope Chain相关资料。
function A(){}
A.prototype=B;
A.prototype.z=8;
b=new A();
alert(b.z); //output 8
alert(b.m); //output 5
alert(B.z); //output 8
for(S in B)
document.write(S+"="+B[S])//m=5z=8