FWIW, in Firefox, you can use the destructuring assignment to do something like what you want.
Array.prototype.addToEach = function(x) { for (var i = 0; i < this.length; i++) this[i] += x; return this; }; var x = "foo", y = "bar"; [x,y] = [x,y].addToEach("baz"); console.log(x,y);
http://jsfiddle.net/uPzNx/ (demo for spidermonkey implementation)
Not that this has anything to do with the solution, but for those who don't like the native .prototype
extensions, you can do it instead.
function addToEach(s) { var args = Array.prototype.slice.call(arguments, 1); for (var i = 0; i < args.length; i++) args[i] += s; return args; }; var x = "foo", y = "bar"; [x,y] = addToEach("baz", x, y); console.log(x,y);
source share