Object.getOwnPropertyDescriptors

# Xavier MONTILLET (13 years ago)

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 ) ); };

# Axel Rauschmayer (13 years ago)

It has already been proposed, look here: strawman:extended_object_api