Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save barakargaman/5489019 to your computer and use it in GitHub Desktop.

Select an option

Save barakargaman/5489019 to your computer and use it in GitHub Desktop.

Revisions

  1. barakargaman created this gist Apr 30, 2013.
    30 changes: 30 additions & 0 deletions javascript inheritance with prototypes
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@

    function A() {
    this.aParam = 'a sababa',
    this.aFunction = function() { return this.aParam; }
    };
    function B() {
    this.bParam = 'b sababa',
    this.bFunction = function() { return this.bParam; }
    };
    function C() {
    this.cParam = 'c sababa',
    this.cFunction = function() { return this.cParam; }
    };
    function D() {
    this.dParam = 'd sababa',
    this.dFunction = function() { return this.dParam; }
    };
    B.prototype = new A();
    C.prototype = new B();
    D.prototype = new C();

    var a = new A();
    var b = new B();
    var c = new C();
    var d = new D();

    // ----------------------
    console.log(d.dParam) // d sababa
    console.log(d.cParam) // c sababa
    console.log(d.aFunction()) // a sababa