Object.getOwnPropertyDescriptors
Xavier MONTILLET
xavierm02.net at gmail.com
Fri Nov 11 11:30:22 PST 2011
Hi,
I think adding Object.getOwnPropertyDescriptors would be great.
It could be implemented like this:
Object.getOwnPropertyDescriptors = function ( object ) {
var propertiesDescriptor = { };
Object.getOwnPropertyNames( object ).forEach( function ( key ) {
propertiesDescriptor[ key ] = Object.getOwnPropertyDescriptor(
object, key );
} );
return propertiesDescriptor;
}
And here are some usecases that would be much longer to write without it:
Function.prototype.inherits = function ( Parent ) {
this.prototype = Object.create( Parent.prototype,
Object.getOwnPropertyDescriptors( this.prototype ) );
return this;
};
Object.prototype.clone = function ( ) {
return Object.create( Object.getPrototypeOf( this ),
Object.getOwnPropertyDescriptors( this ) );
};
More information about the es-discuss
mailing list