Prev: func.apply() throws Error -2147467259
Next: subject
From: G on 30 Jan 2010 08:04 Not an array comprehension. let a = [key for each( key in getKeys() )]; An object comprehension... let o = {key: getValue( key ) for each( key in getKeys() )}; // invalid syntax let o = [{key: getValue( key )} for each( key in getKeys() )]; // valid, but an array of objects instead of an object Is it possible to do an 'object comprehension' In JavaScript? -- G
From: Thomas 'PointedEars' Lahn on 30 Jan 2010 08:24 G wrote: > Not an array comprehension. > > let a = [key for each( key in getKeys() )]; > > An object comprehension... > > let o = {key: getValue( key ) for each( key in getKeys() )}; // > invalid syntax > let o = [{key: getValue( key )} for each( key in getKeys() )]; // > valid, but an array of objects instead of an object > > Is it possible to do an 'object comprehension' In JavaScript? -v please PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: G on 30 Jan 2010 10:10 By "-v please", are you asking which version? Presumably application/javascript;version=1.7 or application/javascript;version=1.8 because 'object comprehensions' (if such a thing is possible) are unlikely to predate array comprehensions. -- G
From: Lasse Reichstein Nielsen on 30 Jan 2010 12:44 G <cultureanew(a)gmail.com> writes: > By "-v please", are you asking which version? He probably meant --verbose, as in: Please give more information (or perhaps: please Write in entire sentences). Anyway, as far as I know, there is no Object comprehension in JavaScript 1.7 or 1.8. You might want to look at Generator Expressions, for some kind of shorthand. /L P.S. But remember that it works it Mozilla browsers only. -- Lasse Reichstein Holst Nielsen 'Javascript frameworks is a disruptive technology'
From: Dmitry A. Soshnikov on 30 Jan 2010 12:49
On Jan 30, 4:04 pm, G <culturea...(a)gmail.com> wrote: > Not an array comprehension. > > let a = [key for each( key in getKeys() )]; > > An object comprehension... > > let o = {key: getValue( key ) for each( key in getKeys() )}; // > invalid syntax > let o = [{key: getValue( key )} for each( key in getKeys() )]; // > valid, but an array of objects instead of an object > > Is it possible to do an 'object comprehension' In JavaScript? > Nope, that's not possible. By the syntax rules {key: ...} will be key 'key' but not dynamic key on each iteration from the getKeys() object. But using array comprehension, it's possible to make it in actions (define first object, and then fill): var o = {}; [o[key] = value for ([key, value] in Iterator({a: 1, b: 2}))]; Which actually isn't so different from simple iteration via: var o = {}; for ([key, value] in Iterator({a: 1, b: 2})) { o[key] = value; } Also simple iteration loop is acceptable. /ds |