var Singleton = cc.Class({
// 成员变量
name : "",
age : 0,
ctor () {
this.name = "Leovany";
this.age = 20;
},
statics: {
Config: null
},
printInfo(){
cc.log("name = " + this.name+",age = " + this.age);
}
});
Singleton.Config = new Singleton();
module.exports = Singleton;
2,调用
var Singleton = require("Singleton");
cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, World!'
},
// use this for initialization
onLoad: function () {
console.log("名字", Singleton.Config.name)
Singleton.Config.printInfo();
Singleton.Config.name="小王"
console.log("名字2", Singleton.Config.name)
},
// called every frame
update: function (dt) {
},
});