Permalink
Browse files

Use `Object.create()` instead of `.__proto__`

  • Loading branch information...
creationix committed Mar 29, 2012
1 parent 639cc13 commit 56e3bb30bf9aa2cb41dec4c4f14e19e1d3c66588
Showing with 3 additions and 1 deletion.
  1. +3 −1 articles/object-graphs-2/classical.js
@@ -17,7 +17,9 @@ function Square(side) {
this.width = side;
this.height = side;
}
-Square.prototype.__proto__ = Rectangle.prototype;
+// Make Square inherit from Rectangle
+Square.prototype = Object.create(Rectangle.prototype, { constructor: { value: Square } });
+// Override a method
Square.prototype.getPerimeter = function getPerimeter() {
return this.width * 4;
};

0 comments on commit 56e3bb3

Please sign in to comment.