Skip to content

Instantly share code, notes, and snippets.

@kof
Created March 24, 2011 13:10

Revisions

  1. kof created this gist Mar 24, 2011.
    24 changes: 24 additions & 0 deletions inherits.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /**
    * Inherit prototype properties
    * @param {Function} ctor
    * @param {Function} superCtor
    */
    _.mixin({
    inherits: (function(){
    function noop(){}

    function ecma3(ctor, superCtor) {
    noop.prototype = superCtor.prototype;
    ctor.prototype = new noop;
    ctor.prototype.constructor = superCtor;
    }

    function ecma5(ctor, superCtor) {
    ctor.prototype = Object.create(superCtor.prototype, {
    constructor: { value: ctor, enumerable: false }
    });
    }

    return Object.create ? ecma5 : ecma3;
    }())
    });