如何不继承cc.Component制作一个单例?

官方的代码

var Singleton = cc.Class({
    extends: cc.Component,

    properties: {
        monsterIcon: {
            default: null,
            type: cc.SpriteFrame
        }
    },

    statics: {
        instance: null
    },

    onLoad: function () {
        Singleton.instance = this;
    }
});

这样切换场景不是有没有了么?unity有donotDestory机制,creater该怎么搞呢?

如果 不继承cc.Component 应该怎么实现呢,麻烦举个例子。谢谢。

http://www.cocos.com/docs/creator/scripting/scene-managing.html

1赞

非常感谢:grinning:。如果不继承cc.Component 应该怎么实现呢?不习惯把单例挂上去。

var dao = {
    version: "1.0.0",
  
    store: function(){
       //
    },
    load: function(){
       //
    },
};
//dao.store();
dao.load();

module.exports = dao;
1赞

直接声明就行了,像楼上那样写。如果你要导出给其它文件引用,可以参考 http://www.cocos.com/docs/creator/scripting/modular-script.html#-javascript-

2赞

谢谢:grinning: