ecomfe/oo

提供直接继承静态对象的功能

Closed this issue · 4 comments

相当于Object.create,以下是摘自MDN的代码:

if (typeof Object.create != 'function') {
    (function () {
        var F = function () {};
        Object.create = function (o) {
            if (arguments.length > 1) { throw Error('Second argument not supported');}
            if (o === null) { throw Error('Cannot set a null [[Prototype]]');}
            if (typeof o != 'object') { throw TypeError('Argument must be an object');}
            F.prototype = o;
            return new F();
        };
    })();
}

现有的是近似支持的, 直接:

var StaticClass = Class.create(obj);

但有些区别,StaticClass 是直接继承了 Class, 对 obj 上挂着的属性是做 mixin,而不是链上prototype。 如果有必要,可以提供一个 Class.static(obj)方法

感觉用继承还是有必要的,这样用于继承的那个对象如果有被修改(有时候有些对象的实现就是运行时会改掉自己),下面也能直接生效

ok,我加个 static 方法

review:

6905872