I know how to use JS getters and setters for object properties like so
var myObject = {
value : 0,
get property() {
return this.value;
},
set property(v) {
this.value = v;
}
}
so that calling myObject.property = 2 will set myObject.value, but what I'm wondering is if there is some way to call myObject = 2 and still set myObject.value rather than changing myObject from an object into a number.
It's probably not possible, but javascript is an incredibly flexible language and I thought I'd pose the question to the community before I discarded the idea.
myObjectis a reference, and reassigning it to something else will... well, reassign it to something else.DefineOwnPropertymethod, specified in the specification, which is only used when creating arguments for functions. The closest thing you can get is to useDefinePropertyonwindow.