![]() |
| | #1 | |||||||
| Movable Type Integration Join Date: Feb 2007
Posts: 264
![]() | Javascript Pointers Quote:
__________________ You're friendly neighborhood automation routine. Last edited by MT Integration : 08-16-2007 at 02:02 AM. Reason: Update to original article | |||||||
| | |
| | #2 | ||
| | Dude! This article is wrong on almost every line. Only primitve types are passed by val. All others (read 'Objects'- i.e.: damn near every goddamned var of note) as passed by ref. Also, eval just calls the javascript interpreter on the string you pass it, in the context you call it. So writting out some code in quotes and calling eval doesn't get you free pointers. You should pull this article down, its bad for the web and the community of js developers who rely on it. -j | ||
| |
| | #3 | ||
| Runs This Show | I'll respectfully disagree for the moment, while allowing myself some wiggle room to be wrong. It's happened before To describe the situation that brought this to light... I had a large object containing a large amount of arbitrary data. I passed that object by parameter into a function. I updated the object. The object remained updated within the function, but not outside of the function. The only thing I can surmise by this sequence is that the object itself was not passed in by reference, but by value. In my situation, the object can become arbitrarily large. I don't want to pass an arbitrarily large object by value, then return that object to reset it's parent - that causes excessive memory use, and a lot of unnecessary operations to copy that large object. The use of eval allows me to reference the object without copying the object twice and using twice the memory - in essence pointers. It certainly is of limited usefulness. In most scenarios objects are pretty small so these operations aren't expensive enough to require working around them. In my particular situation, it makes sense both for size and speed. I've read on multiple occasions that objects are passed by reference. My testing showed that not to be the case. Having said all of that, I'll revisit the subject and see if my value-based parameter passing was happening for some other reason. I know that I was working with complex objects and it's possible that the base object I was working with was in fact derived initially from Array rather than Object - if that is the case I'll revise and add clarification for the different scenarios of usefulness. | ||
| | |
| Thread Tools | |
| Display Modes | |
| |