I was browsing the JIT's code, and I saw this:
var isGraph = ($type(json) == 'array');
var ans = new Graph(this.graphOptions);
if(!isGraph)
//make tree
(function (ans, json) {
ans.addNode(json);
for(var i=0, ch = json.children; i<ch.length; i++) {
ans.addAdjacence(json, ch[i]);
arguments.callee(ans, ch[i]);
}
})(ans, json);
else
//make graph
(function (ans, json) {
var getNode = function(id) {
for(var w=0; w<json.length; w++) {
if(json[w].id == id) {
return json[w];
}
}
return undefined;
};
What could be the purpose for those anonymous functions? They immediately pass out of scope, right?
Why use:
(function (ans, json) {
ans.addNode(json);
for(var i=0, ch = json.children; i<ch.length; i++) {
ans.addAdjacence(json, ch[i]);
arguments.callee(ans, ch[i]);
}
})(ans, json);
instead of:
ans.addNode(json);
for(var i=0, ch = json.children; i<ch.length; i++) {
ans.addAdjacence(json, ch[i]);
arguments.callee(ans, ch[i]);
}
Is this some super elite JS hack?