Le 29/11/2012 06:20, Brandon Benvie a écrit :
The answer though in that case is easy enough though, make sure the
prototype descriptor is created with Object.create(null). This
wouldn't solve compatibility issues with in-the-wild code but it
solves the issue for most people who care enough to use anything
dealing with descriptors.
Object.freeze(Object.prototype) is also a solution.
Incidentally, it protects also existing built-ins.
For property descriptors, I've also seen an interesting style in the
dom.js code [1]. Basically, there are helper functions (attribute,
constant) which generate the property descriptor to be used as second
argument of Object.create. This case is very WebIDL-centric, but that
could probably work in other cases. In these cases, the function
generating property descriptors could use Object.create(null) under the
hood.
David
[1]
https://github.com/andreasgal/dom.js/blob/84b7ab6cf9fa2f41aa4dfbe661f2747b938ca292/src/impl/Node.js
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss