I want to make a custom Array object that recieves a number as index, and depending on the value of the index, it would return a computed value.
For example:
>>> var MyArray(2); >>> MyArray[2]; 4 >>> MyArray.2; 4 I know that for the showed example, I'm better of with a function, but I want to know if I can override the properties/index lookup for some things that are conceptualy arrays, but could need some computation.
I'm aware that x.1 == x[1], so what I need is to make a property in javascript.
I mean, make x.variable = x.myPropery(), so everytime that I get the value of x.variable, I recieve the return of x.myPorperty().
Is this even possible?