如何定义Bearcat类

使用 BearCat 定义 NodeJS 类

以下是以 context.json 方式配置的加载, 其他形式加载与此类似

{
    "name": "simple",
    // 对象具体配置
    "beans": [
        // 每一个bean定义, 都是一个对应的类
        {
        // 唯一标识ID, 使用BearCat.getBean("$name"); 来获取/实例化对象
    "id": "car",
    // 对象对应的类方法
    "func": "car",



    // 集成的父类
    "parent": "base",
    // 工厂类
    "factoryBean": "carFactory",
    // 工厂方法
    "factoryMethod": "createCar",
    // 类中属性的定义(ref表示引用自定义类, type表示内置类型, value为默认的值)
    "args": [{    -> function Car(engine){}
        "name": "engine",
        "ref": engine
    }, {
        "name": "num",
        "type": "Object|Number|Array|Boolean|Function|String"
        "value": 100
    }],
    // 是args的别名
    "props": [{
        "name": "wheel",
        "ref": "wheel"
    },{
        "name": "door",
        "value": 4
    }]
    // 表示是否是单例, 默认单例
    "scope": "prototype|singleton",
    // 是否延迟初始化
    "lazy": true,
    // 初始化时调用方法
    "init": "ctor",
    // 销毁时调用方法
    "destroy": "dtor",
    // 延时初始化时的顺序
    "order": 2
    },
    // 其他更多的类定义
    {
    "id": "engine",
    "func": "engine",
    // 继承的父类
    "parent": "base",
    // 是否是异步
    "async": true,
    // 异步顺序
    "order": 1
    }, {
    "id": "wheel",
    "func": "wheel",
    "parent": "base",
    "async": true,
    "order": 1
    }, {
    "id": "base",
    "func": "base",
    "args": [{"name": "price", "value": 0}]
    }]
}
Donate - Support to make this site better.
捐助 - 支持我让我做得更好.