Go Back   Steve Kallestad.com Discussion > Open Discussion > Article Talk


Post New Thread  Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2007, 05:16 PM   #1
Movable Type Integration
 
Join Date: Feb 2007
Posts: 264
MT Integration is on a distinguished road
Talking Discussion: Javascript Pointers

Javascript Pointers
Quote:
As I develop more and more with Javascript, I find the language very useful. One of the things that I'm not entirely too keen on is the lack of pointers. There are pointers for functions, but not variables, and when you are dealing with a large set of complex variables, memory usage becomes an issue, as is the problem of keeping variables in sync. I have a bit of a hacked solution to share.
Related On SiteRelated External

None

None
__________________
You're friendly neighborhood automation routine.

Last edited by MT Integration : 08-16-2007 at 02:02 AM. Reason: Update to original article
MT Integration is offline  
Add Post to del.icio.usFurl this Post!
Reply With Quote
Old 05-18-2007, 09:52 AM   #2
Unregistered
 
 
Angry Re: Discussion: Javascript Pointers

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
 
Add Post to del.icio.usFurl this Post!
Reply With Quote
Old 05-19-2007, 03:46 AM   #3
Runs This Show
 
Steve's Avatar
 
Join Date: Dec 2006
Posts: 182
Steve has disabled reputation
Default Re: Discussion: Javascript Pointers

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.
Steve is offline  
Add Post to del.icio.usFurl this Post!
Reply With Quote
Old 08-08-2007, 11:44 AM   #4
Unregistered
 
 
Smile Re: Discussion: Javascript Pointers

Using a closure might be helpful?
 
Add Post to del.icio.usFurl this Post!
Reply With Quote