Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace `.__proto__` with `Object.create()` in prototypal example.

  • Loading branch information...
commit e4141097476b19f5c1dcccfd069b3c297ddb31e4 1 parent 9fe23f8
@creationix authored
Showing with 7 additions and 9 deletions.
  1. +7 −9 articles/object-graphs-2/prototypal.js
View
16 articles/object-graphs-2/prototypal.js
@@ -12,16 +12,14 @@ var Rectangle = {
}
};
//square
-var Square = {
- name: "Square",
- getArea: function getArea() {
- return this.width * this.width;
- },
- getPerimeter: function getPerimeter() {
- return this.width * 4;
- },
+var Square = Object.create(Rectangle);
+Square.name = "Square";
+Square.getArea = function getArea() {
+ return this.width * this.width;
+};
+Square.getPerimeter = function getPerimeter() {
+ return this.width * 4;
};
-Square.__proto__ = Rectangle;
//test
var rect = Object.create(Rectangle);
rect.width = 6;
Please sign in to comment.
Something went wrong with that request. Please try again.