J
Jason S
I'm pretty sure the answer is no, but is there any way to overload []
or . in an object?
e.g. if I had some object o with a property v, to map the syntax
o.v["something"] or o.v."something", so that it calls
o.get('something') or o.set('something',newval)?
like
o.v.squash = 3 would actually call o.set('squash',3)
o.v.squoosh+1 would actually call o.get('squoosh')+1
o.v[x] += 7 would actually do o.set(x,o.get(x)+7)
I know about getters and setters, so you can do this for specific
individual properties of an object (the first two examples above), but
I'm wondering if there's a way to do it in general (e.g. the third
example).
or . in an object?
e.g. if I had some object o with a property v, to map the syntax
o.v["something"] or o.v."something", so that it calls
o.get('something') or o.set('something',newval)?
like
o.v.squash = 3 would actually call o.set('squash',3)
o.v.squoosh+1 would actually call o.get('squoosh')+1
o.v[x] += 7 would actually do o.set(x,o.get(x)+7)
I know about getters and setters, so you can do this for specific
individual properties of an object (the first two examples above), but
I'm wondering if there's a way to do it in general (e.g. the third
example).