Definition
//SingleTon.js
var SingleTon = cc.Class({
extends: cc.Component,
properties: {
},
statices:{
instance: null,
getInstance: function(){
if(SingleTon.instance == null) SingleTon.instance = new SingleTone();
return SingleTon.instance;
},
},
foo: function(){
cc.log("hello world");
}
// TODO..
});
usage
//Main.js
var SingleTon = require("SingleTon");
cc.Class({
extends: cc.Component,
myFunction: function(){
SingleTon.getInstance().foo();
}
});
cocos Failed to notify project evaluation listener. java.lang.exceptionInInitializerError (0) | 2021.05.07 |
---|---|
How to define cocos creator constant variable? (0) | 2021.05.04 |
[cocos creator js ] how to UI Components , button Hide & Active ? (0) | 2021.04.16 |
cocos creator js (0) | 2021.04.09 |
cocos2dx 3.17 64bit build in Android Studio. (0) | 2019.06.17 |
cocos2dx Android.mk All cpp files Attach (0) | 2019.04.26 |