A lot of code is minified using automagic tools, and few of them preserve function names. Relying on the name of identifiers for runtime behaviour (outside of diagnostics, etc.) will likely cause hard-to-find bugs when using such tools.
On Wed, Jun 6, 2012 at 4:33 AM, Brandon Benvie <[email protected]> wrote: > Object.decorate seems to fit the bill I think. > > On another note, using an array and the as of yet non-standardized but still > useful function name property is a lot more palatable and succinct and is > much closer to the desired improved object literal syntax. I've been partial > to the following reimagining of Object.extend as Object.decorate which > supports arrays of named functions as well as objects and also > setters/getters which existing extend functions don't support usually. > > Object.defineProperty(Object, 'decorate', { > configurable: true, > writable: true, > value: function decorate(o){ > var a, b, c, d; > for (a in arguments) { > if (a) { > if (Array.isArray(b = arguments[a])) { > // array of named functions > for (c = 0; c < b.length; c++) { > if (typeof b[c] === 'function' && b[c].name) { > Object.defineProperty(o, b[c].name, { value: b[c], > configurable: true, writable: true }); > } > } > } else { > // object > for (c in b) { > // use getDesc instead of hasOwn to support get/set > if (d = Object.getOwnPropertyDescriptor(b, c)) { > if (d.get || d.set) { > Object.defineProperty(o, c, d); > } else { > // purposefully trigger accessors if they exist > o[c] = d.value; > } > } > } > } > } > } > return o; > } > }); > > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

