Re:PythonJS now faster than CPython
by bcj on Sunday June 08, 2014 @04:35PM
(#7865816)
My JS knowledge isn't great. In python, I can do operator overloading such that `obj[item] = value` does something completely different than assignment. Is that possible with JavaScript?
[ Parent
| on HN ]
You can set a custom getters and setters, but I wouldn't call it operator overloading. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
So...
> var x = {}
> Object.defineProperty(x, 'value', { get: function() { return 1 }, set: function() { console.log('set') } })
> x.value
1
> x.value = 2
set
> x.value
1