Permalink
Browse files

Update the diagrams a little more.

This should pretty things up a little.
  • Loading branch information...
1 parent 404fdae commit 70a4301241b29467d78e30d1ea05ceb48a2efcfb @creationix creationix committed Oct 9, 2010
@@ -87,8 +87,6 @@ Here we'll create a few objects that all share a common function. This function
<br style="clear:left"/>
-*(Note I drew the objects and literals inside the closure to make the diagram clearer. There is no special meaning to this. Only free variables and function bodies are affected by closure nesting)*
-
In the diagram, we see that even though `Fred.description` was set to `Lane.description`, it's really only referencing the function. Thus all three references have equal ownership of the anonymous function. This is why I try to not call functions on constructor prototypes "methods", because that implies some sort of binding of the function to the constructor and it's "class". *(see [what is this][] for more details on the dynamic nature of `this`)*
## Conclusion
@@ -4,24 +4,26 @@ digraph finite_state_machine {
/* Execution Contexts */
node [shape=Mrecord, fillcolor=beige, style=filled];
- top [label="<__proto__>[Scope]|<description1>description1|<description2>description2"];
- closure1 [label="<__proto__>[Scope]|<name>name"];
- closure2 [label="<__proto__>[Scope]|<name>name"];
+ top [label="<__proto__>[ Scope ]|<description1>description1|<description2>description2|<makeClosure>makeClosure"];
+ closure1 [label="<__proto__>[ Scope ]|<name>name"];
+ closure2 [label="<__proto__>[ Scope ]|<name>name"];
/* Normal Objects */
node [shape = Mrecord, fillcolor=lightskyblue, style=filled];
/* Function Objects */
node [shape = Mrecord, fillcolor=orange, style=filled];
- fn1 [label="<__proto__>[Function ()]|\{return name\}|<__scope__>[scope]"];
- fn2 [label="<__proto__>[Function ()]|\{return name\}|<__scope__>[scope]"];
+ fn_makeClosure [label="<__proto__>[ makeClosure(name) ]|\{ return function () \{\} \}"];
+ fn1 [label="<__proto__>[ λ() ]|\{return name\}|<__scope__>[scope]"];
+ fn2 [label="<__proto__>[ λ() ]|\{return name\}|<__scope__>[scope]"];
/* Literals */
node [shape = plaintext, fillcolor=gray92, style="filled,rounded"];
cloe [label="\"Cloe the Closure\""]
albert [label="\"Albert the Awesome\""]
/* References */
+ top:makeClosure -> fn_makeClosure:__proto__;
top:description1 -> fn1:__proto__;
top:description2 -> fn2:__proto__;
closure1:name -> cloe;
@@ -4,17 +4,17 @@ digraph finite_state_machine {
/* Execution Contexts */
node [shape=Mrecord, fillcolor=beige, style=filled];
- top [label="<__proto__>[Scope]|<Lane>Lane|<description>description|<Fred>Fred"];
+ top [label="<__proto__>[ Scope ]|<Lane>Lane|<description>description|<Fred>Fred"];
/* Normal Objects */
node [shape = Mrecord, fillcolor=lightskyblue, style=filled];
- ob_Lane [label = "<__proto__>[Object]|<name>name|<description>description"];
- ob_Fred [label = "<__proto__>[Object]|<description>description|<name>name"];
- ob_1 [label = "<__proto__>[Object]|<name>name"];
+ ob_Lane [label = "<__proto__>[ Object ]|<name>name|<description>description"];
+ ob_Fred [label = "<__proto__>[ Object ]|<description>description|<name>name"];
+ ob_1 [label = "<__proto__>[ Object ]|<name>name"];
/* Function Objects */
node [shape = Mrecord, fillcolor=orange, style=filled];
- fn1 [label="<__proto__>[Function ()]|\{return this.name\}"];
+ fn1 [label="<__proto__>[ λ() ]|\{return this.name\}"];
/* Literals */
node [shape = plaintext, fillcolor=gray92, style="filled,rounded"];
@@ -4,8 +4,8 @@ digraph finite_state_machine {
/* Execution Contexts */
node [shape=Mrecord, fillcolor=beige, style=filled];
- top [label="<__proto__>[Scope]|<name>name|<age>age|<isProgrammer>isProgrammer"];
- global [label="<__proto__>[Scope global]|<likesJavaScript>likesJavaScript"];
+ top [label="<__proto__>[ Scope ]|<name>name|<age>age|<isProgrammer>isProgrammer"];
+ global [label="<__proto__>[ global ]|<likesJavaScript>likesJavaScript"];
/* Literals */
node [shape = plaintext, fillcolor=gray92, style="filled,rounded"];
@@ -4,12 +4,12 @@ digraph finite_state_machine {
/* Execution Contexts */
node [shape=Mrecord, fillcolor=beige, style=filled];
- top [label="<__proto__>[Scope]|<tim>tim|<jack>jack"];
+ top [label="<__proto__>[ Scope ]|<tim>tim|<jack>jack"];
/* Normal Objects */
node [shape = Mrecord, fillcolor=lightskyblue, style=filled];
- obj1 [label = "<__proto__>Object|<name>name|<age>age|<isProgrammer>isProgrammer|<likesJavaScript>likesJavaScript"];
- obj2 [label = "<__proto__>Object|<name>name|<age>age"];
+ obj1 [label = "<__proto__>[ Object ]|<name>name|<age>age|<isProgrammer>isProgrammer|<likesJavaScript>likesJavaScript"];
+ obj2 [label = "<__proto__>[ Object ]|<name>name|<age>age"];
/* Literals */
@@ -4,7 +4,7 @@ digraph finite_state_machine {
/* Execution Contexts */
node [shape=Mrecord, fillcolor=beige, style=filled];
- top [label="<__proto__>[Scope]|<name>name|<age>age|<isProgrammer>isProgrammer|<likesJavaScript>likesJavaScript"]
+ top [label="<__proto__>[ Scope ]|<name>name|<age>age|<isProgrammer>isProgrammer|<likesJavaScript>likesJavaScript"]
/* Literals */
node [shape = plaintext, fillcolor=gray92, style="filled,rounded"];

0 comments on commit 70a4301

Please sign in to comment.