创建 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
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 );