Permalink
Browse files

Merge branch 'master' of github.com:creationix/howtonode.org

  • Loading branch information...
2 parents af136c8 + 9fe23f8 commit 83b46efaa8175e8b021843be5925ea2e2d4d300c Tim Caswell committed Mar 29, 2012
Showing with 6 additions and 4 deletions.
  1. +3 −3 articles/object-graphs-2.markdown
  2. +3 −1 articles/object-graphs-2/classical.js
@@ -1,7 +1,7 @@
Title: Learning Javascript with Object Graphs (Part II)
Author: Tim Caswell
Date: Mon Oct 11 2010 08:24:25 GMT-0700 (PDT)
-Node: v0.2.3
+Node: v0.6.14
The first article using graphs to describe JavaScript semantics was so popular that I've decided to try the technique with some more advanced ideas. In this article I'll explain three common techniques for creating objects. They are constructor with prototype, pure prototypal, and object factory.
@@ -21,7 +21,7 @@ Usage is straightforward. Just create an instance of each and call a function o
<object-graphs-2/classical.js#test*>
-This is the resulting data structure. Dashed lines mean object inheritance.
+This is the resulting data structure. Dashed lines mean object inheritance.
![classical](object-graphs-2/classical.dot)
@@ -80,4 +80,4 @@ Here is the object graph that results from this code. Notice that we have acces
## Conclusion
-There is so much more I want to explore, but I like to keep these articles somewhat short and bite-size. If there is demand, I'll write a part three explaining how to do ruby-style mixins and other advanced topics.
+There is so much more I want to explore, but I like to keep these articles somewhat short and bite-size. If there is demand, I'll write a part three explaining how to do ruby-style mixins and other advanced topics.
@@ -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 83b46ef

Please sign in to comment.