If I create an instance of a reference type in a memory-managed language like JavaScript:
var foo = {};
I presume something like the following is added to the stack:
foo | <memory address of the actual instance on the heap>
So foo
is a reference to an area of memory elsewhere.
With pointers in a language like C, you have to explicitly dereference the pointer to get hold of the memory on the heap it points at.
So is it correct to say that the variable foo
is "automatically dereferenced" in a language like JavaScript? Or is that just an implied behavior when the term reference is used instead of pointer?
/**
* `foo` is dereferenced to the memory
* corresponding to the instance on the
* heap. The interpreter expects to find
* an object at that location, parses the
* memory as such, finds the method `bar`
* and invokes it.
*/
foo.bar();