var TitleLayer = cc.Layer.extend({ selectCount: 0, // 使いたい変数 ctor: function() { // 呼ばれる関数 var calledFunc = function() { cc.log(this.selectCount); // これをログに出す } // 略〜〜〜〜 var hogeButton = cc.MenuItemImage.create( res.hoge, res.bar_png, function() { calledFunc(); // ここから関数を呼ぶ }, this) // 略〜〜〜〜 });
ログには
cocos2d: JS: NaN
となった。
TitleLayerのfunction内(今回はcalledFunc)でthis.selectCountを呼び出すと、
TitleLayerではなくcalledFunc関数のselectCountを指定していることになっている?
「undefined」ではなく「NaN」となっているのも不思議。