不允许
this在函数内分配值。假设您 可以 执行此操作,并且您的代码如下所示:
Array.prototype.foo = function() { return this = [1, 2, 3];}var a = ["beans", "rice"];a.foo();// a now points to an object containing [1, 2, 3]现在,如果您这样做:
var a = ["beans", "rice"];var b = a; // b refers to the same object as ab.foo();// what does b refer to now? how about a?
.foo()在对象上调用函数的行为不应更改对象的 身份
。如果
b突然开始引用一个不同的对象而不是
a仅仅因为调用了某种方法,这对于调用者来说将非常混乱。



