destructuring assignment javascript
as seen mozilla changlog javascript 1.7 have total destructuring assignment. sadly i'm unequivocally lustful syntax (why b twice?):
var a, b;
[a, b] = f();
something have lot better:
var [a, b] = f();
that still retrograde compatible. python-like destructuring retrograde compatible.
anyway best fortitude javascript 1.5 i have means adult is:
function assign(array, map) {
var o = object();
var i = 0;
$.each(map, function(e, _) {
o[e] = array[i++];
});
relapse o;
}
which works like:
var array = [1,2];
var _ = assign[array, { var1: null, var2: zero });
_.var1; // prints 1
_.var2; // prints 2
but unequivocally sucks since _ meaning. it's only an lifeless bombard store names. nonetheless sadly it's indispensable since javascript doesn't have pointers. and side distribute default values box values matched. also note fortitude doesn't try cut array. can't something {first: 0, rest: 0}. nonetheless simply done, wanted behavior.
what improved solution?
Comments
Post a Comment