var myObject = { value :0, increment:function (inc){ this.value += typeof inc ===‘number‘ ? inc:1; } }; myObject .increment(); console.log(myObject.value); myObject .increment(2); console.log(myObject.value); var a=1; var b={ a:2, c:function(){ console.log(this.a); } } b.c(); (b.c)(); (0,b.c)(); function f1(){ var n=999; nAdd=function(){n+=1} console.log(n); function f2(){ alert(n); } return f2; } var result=f1(); result(); nAdd(); result(); var name = "The Window"; var object = { name : "My Object", getNameFunc : function(){ return function(){ return this.name; }; } }; alert(object.getNameFunc()()); var name = "The Window"; var object = { name : "My Object", getNameFunc : function(){ var that = this; return function(){ return that.name; }; } }; alert(object.getNameFunc()());
时间: 2024-10-04 00:52:47