| > marginally better. I'm not so sure. As written it's wasteful of resources and not cross-browser. (also not entirely functional) All the stuff with the closure and defineProperty is basically pointless.... In the end what they have is an object with numbers for properties, and they are sticking values in those properties. That's an array. All the hoops they jump through don't do anything except heat up the processor and waste resources, with nothing in return for that. Consider this code which does the same thing: var $ = function(val) {
var addr = $.mem.length;
$.mem[ addr ] = val;
return addr;
}
$.mem = [];
var foo = "foo";
foo = $( foo );
console.log( foo ) // 0
console.log( $.mem[foo] ) // "foo"
This code accomplishes the same thing but is much faster, leaner, simpler, and cross-browser.I'd also say that all of this doesn't really do much to inform one about "pointers". Learning about the link between pointers and arrays in certain other languages might be helpful for some JS developers, but there's none of that here. Here is just a roundabout array implementation that doesn't really teach the reader anything. I'm not going to spit on the efforts of someone who is trying to learn something, or be condescending about it (at least not intentionally)....but I think it's necessary to point this sort of thing out so everyone walks away the wiser. |