Thanks for your reply. I understand JavaScript value/reference semantics though, but not the implementation of it in V8. I was wondering where the difference between value and reference types is made. I suppose reference-types (JavaScript object and arrays) are implemented as a reference-to-object whereas primitives directly contain the value, but I couldn't find this anywhere. For example: in objects.h HeapNumber and Array both derive from HeapObject, but HeapNumber is a value-type (I suppose) whereas Array is a reference type.
Thanks, Jan On Thu, Feb 19, 2009 at 4:00 PM, William Hesse <[email protected]> wrote: > JavaScript objects, primitive values, and properties are all very > different, and should > be explained well in good JavaScript books. The simplest way to achieve > what you > want (two variables aliased to the same information) is: > > var a = new Object(); > var b = a > // a and b point to the same object. That object's properties can be > created and changed. > a.x = 3; > // b.x == 3 and a.x == 3 > b.x = 5; > // b.x == 5 and a.x == 5 > > Only a property of an object can be changed without changing the object's > identity. > Two variables or properties can point to the same object. > > Hope this helps, > Bill Hesse > > > On Wed, Feb 18, 2009 at 11:08 PM, Jan de M. <[email protected]> wrote: > >> >> Hello, >> >> First, thanks for creating this great engine. I am evaluating using it >> for one of my projects, so I started reading the source and I could >> figure out most things myself, but I still don't quite understand how >> variables, values and objects relate to each other. See this code, for >> example: >> >> var a = 0; >> var b = 1; >> >> This creates two locals, but is there any mapping from variable to >> memory address? I found the SymbolTable class but I don't see how it >> is used here. For example, would it be possible to let a point to the >> exact same memory location (object) as b? >> >> Any help would be appreciated. >> >> Jan >> >> > > > -- > We can IMAGINE what is not > > > > --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
