I am trying to code an object with a pointer-like behaviour. It is not meant to be a real pointer as used in other languages, but I need something that refers to a piece of data, so that I can pass that thing around and be sure it is always refering to the very same piece of data.
Consider the following code:
var Pointer = function (data) {
var instance = {};
instance.deref = function () { return data; };
return instance;
};
What I am doing now, is storing the data in the scope of the pointer instance.
My question is: Does storing the data in the scope of the pointer have any significant downsides in terms of speed when I have to move a bunch of pointers from one place to the other? Imagine a data structure where the data is represented by these pointers, all having a unique piece of data in their scope, and I have to manipulate the structure by moving pointers around.