Object.prototype.get & bye bye Object.defineProperty

David Bruant bruant.d at gmail.com
Thu Nov 29 01:11:09 PST 2012


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


More information about the es-discuss mailing list