0
How can I make my object acts like an array (but not only) ?
Imagine I create a class Rect which has one attribute : this.rect (an array [x, y, w, h]). And some get / set attributes : this.top returns this.rect[y]. How can I do this : r = new Rect (1, 2, 3, 4); console.log(r) => [1, 2, 3, 4] console.log(r[0]) => 1 console.log(r.top) => 2 Hope you understood (I am french). Thank.
5 Answers
+ 3
it is an array not object
+ 3
a lesson about object
https://www.sololearn.com/learn/JavaScript/1151/
a lesson about arrays
https://www.sololearn.com/learn/JavaScript/1239/
0
It has to be an object for r.top
0
UP š
0
I think you didn't understand. I want my obect to ALSO acts like an array. For exemple in Python with the special method __getitem__.