javascript 的“this”关键字与 java 的“this”关键字有何不同?任何实际示例将不胜感激。
var counter = {
val: 0,
increment: function () {
this.val += 1;
}
};
counter.increment();
console.log(counter.val); // 1
counter['increment']();
console.log(counter.val); // 2
in java:
public Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
thanks.
In JavaScript this
总是指我们正在执行的函数的“所有者”,或者更确切地说,指函数所属的对象。
In Java, this
指的是执行该方法的当前实例对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)