CocosCreator 创建全局对象 == 同单例效果一致

创建 SceneController.js

cc . Class ({
extends: cc . Component ,

properties: {
index : 999 ,
},

// use this for initialization
onLoad: function () {

},
init: function () {


}
// called every frame, uncomment this function to activate update callback
// update: function (dt) {

// },
});
添加全局变量定义
window . SceneController = new ( require ( 'SceneController' ))()

test.js
测试
cc . log ( "======222" + SceneController . index );
SceneController . index ++ ;
cc . log ( "======222" + SceneController . index );


你可能感兴趣的:(cocosCreator)