标签:
var myObject = { foo: "bar", func: function() { var self = this; console.log("outer func: this.foo = " + this.foo); // bar console.log("outer func: self.foo = " + self.foo); // bar (function() { console.log("inner func: this.foo = " + this.foo); // undefined console.log("inner func: self.foo = " + self.foo); // bar }()); } };
myObject.func();
var a=10; var foo={ a:20, bar:function(){ var a=30; return this.a; } } foo.bar() // 20 (foo.bar)() // 20 (foo.bar=foo.bar)() //10 (foo.bar,foo.bar)() // 10
标签:
原文地址:http://www.cnblogs.com/beyond-succeed/p/5820155.html