I've got 2d array of object like chessboard.
You can get object by data.field(x,y); (object are stored inside 2d array of objects)
I want each of fields to have functions: top, bottom, left, right that will return neighbour field.
For example data.field(3,3).top().left().bottom().name would return name of field(4,3).
But: Have I to declare those function for each of objects? I mean, for example on 8x8 field that would be 64 instances of the same function:
data.field(0,0).top = function(){...}
data.field(0,1).top = function(){...}
...
Ofc I can easily declare them inside loop, but its pure waste of memory and I'm sure its not the way to do it. Is it possible to declare this functions only once to be available inside every object returned by field(x,y) function?