mutoo
1/31/2015 - 3:17 PM

javascript prototype simulate

javascript prototype simulate

var namespace = (function () {
    'use strict';

    var objPrototype = Object.create(null);
    var funcPrototype = Object.create(objPrototype);

    var Obj = new Function();
    Obj.__proto__ = funcPrototype;
    Obj.prototype = objPrototype;
    objPrototype.constructor = Obj;

    var Func = function () {
        var func = new Function();
        func.__proto__ = funcPrototype;
        func.prototype = Object.create(objPrototype);
        return func;
    };

    Func.__proto__ = funcPrototype;
    Func.prototype = funcPrototype;
    funcPrototype.constructor = Func;

    var namespace = Object.create(objPrototype);
    namespace.Object = Obj;
    namespace.Function = Func;

    return namespace;
})();