こんにちは、次のようなコードがあります。
var myClass = {
globalVar : {
total : 100
},
myFunction : {
getTotal : function() {
return this.globalVar.total;
}
},
};
// Uncaught TypeError: Cannot read property 'total' of undefined
alert(myClass.myFunction.getTotal() );
キーワードはundefinedthis
を返します。なぜですか? の代わりに使っているからですか?var myClass
function myClass()
ありがとう
[編集] ここに JSFiddle がありますhttp://jsfiddle.net/DarcFiddle/cg7Fk/