Created
January 13, 2012 18:14
-
-
Save huckfinnaafb/1607858 to your computer and use it in GitHub Desktop.
This file contains 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 characters
function Graph(width, length) { | |
this.width = width; | |
this.length = length; | |
this.elements = 2; // I want to keep this | |
this.nodes = new Array(width * length); | |
var i; | |
for (i = 0; i < this.nodes.length; i += 1) { | |
this.nodes[i] = new Node(this, i); | |
} | |
} | |
Graph.prototype.save = function () { | |
return JSON.stringify(this, replacer, 4); | |
}; | |
function replacer(key, value) { | |
var excludes = ["graph", "elements"]; | |
if (excludes.indexOf(key) >= 0) { | |
return undefined; | |
} | |
return value; | |
} | |
function Node(graph, index) { | |
this.graph = graph; // Exclude from JSON | |
this.index = index; | |
this.elements = []; // Exclude from JSON | |
} | |
var world = new Graph(9, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment