-1
当“this”引用javascript字符串对象时,是否有任何方法可以更改“this”的值?当“this”引用“this”时如何更改javascript字符串值
this = "abc";
抱怨左转非法任务。
编辑:为了澄清,我正在尝试以下,但它看起来像没有办法做到这一点。
String.prototype.replaceAll = function (find, replace) {
while (this.indexOf(find) > -1) {
this = this.replace(find, replace); // illegal
}
}
正如错误所述,你不能改变'this'的值(即赋值给它)。 –
你不能改变'this'等价于什么。 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)[Here是MDN]谈论它 –
相关:[为什么我不能指定一个新的值给“这个“在原型函数?”(http://stackoverflow.com/q/9713323/218196) –