Created
November 15, 2012 22:33
-
-
Save nmtitov/4081895 to your computer and use it in GitHub Desktop.
Revisions
-
nt9 created this gist
Nov 15, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ // конструктор родительского класса var A = function () { this.x = 10; this.y = 10; this.area = function () { return this.x * this.y; } } // A.prototype.area = function () { // return this.x * this.y; // } var a = new A(); console.log('area of super class', a.area()); var B = function () { A.call(this); // вызываем конструктор родителя } B.prototype = Object.create(A.prototype); // наследуем, т.е. используем прототип родителя // меняем имплементацию метода в родителе A.prototype.area = function () { return Math.pow(this.x, this.y); } var b = new B(); console.log('area of child class', b.area());