我不明白爲什麼我可以通過b或c。在目標對象的全局功能無法訪問變量,得到了一些麻煩,在JS對象變量繼承。無法訪問的變量在Javascript對象
var object = {
a: 'a',
global: function() {
var b = 'b';
this.c = 'c';
},
render: function() {
console.log('render()');
return this.a + '/' + this.global.b + '/' + this.global.c;
}
};
它呈現: A /未定義/未定義
Global是一個函數。函數返回的東西。 'b'只能在函數內訪問,而不能從外部訪問。 'this.c'也一樣。 'this.c'!='global.c' – Mouser 2015-02-09 23:57:27