Re: pointer syntax



Maarten said:
>Yes. You have the "var" modifier on parameters exactly backwards. The
>default is call by value. Var makes a parameter call by reference.

Aha! OK, I think it makes sense now. :)

To summarize (let's see if I've got it right) --
In the context of general business programming (I'm not writing
drivers, or OSs, or anything complex):

* If I have an object, don't worry about var for general-purpose use,
and please don't make copies unless I know what I'm doing. Working with
objects is really working with references.

* Use var with objects, only if I intend to change the reference
(beware of orphaned memory!)

* If I have anything else, use var if I need changes to come back.
Avoid explicit pointers like the plague. (Again, unless I have some
special reason to need them, like strange API calls:) )

-Corinna

.



Relevant Pages

  • Re: window object
    ... Within a script, every reference to an object amounts to two ... calls from the scripting engine to the DHTML Object Model. ... var sText = document.all.div1.innerText; ...
    (comp.lang.javascript)
  • Re: can you add whole types of elements to addEventListener? if not, how else to achieve the efffect
    ... var eventTargetRef = e.target; ... the proprietary `document' reference (where for the latter there is alas ... caused the event is an implementation of W3C DOM Level 2 Event's ... proprietary event-handling property is available. ...
    (comp.lang.javascript)
  • Re: RTL and offsetLeft in IE 6
    ... var body = document.body, ... the return value may as well not be a reference to a host object. ... property access below, so it needs to be tested or the property access could ...
    (comp.lang.javascript)
  • Re: pointer syntax
    ... > really passing a reference (which is like an old-school pointer, ... > a copy of the primitive's value and passing that. ... build them yourself with pointers. ... mean a var parameter, write a var parameter. ...
    (comp.lang.pascal.delphi.misc)
  • Re: How to free memory in Javascript?
    ... The only memory allocated here is the space allocated for i. ... How do i get rid of the reference to button? ... Whilst in some sense reference counting is a garbage collection pattern ...
    (microsoft.public.scripting.jscript)