I am trying to do...
a=['a',2,3];
a+=function(){return 'abc'};
console.log(a[3]);
Ergo I want to a.push() in a shorthand way.
Is there any kind of operator that will allow me to do this?
a.push(value) is the shorthand way haha. The other way is a[a.length] = value
aReallyReallyLongVariableName, not having to (mis)type it twice is convenient.No, ES5 getter-setters allow you to intercept assignments = but there is no operator overloading to allow intercepting and reinterpreting + or +=.
If you knew the content being added was a single primitive value, you could fake it.
var appendable = {
x_: [1, 2],
get x() { return this.x_; },
set x(newx) { this.x_.push(newx.substring(("" + this.x_).length)); }
};
alert(appendable.x);
appendable.x += 3;
alert(appendable.x); // alerts 1,2,3 not 1,23
alert(appendable.x.length);
but really, .push is the best way to push content onto the end of an array.