Reputation: 861
var properties = Object.getOwnPropertyNames(Array);
console.log(properties);
Why does this code list the properties of the Array.prototype
object too? According to my understanding it should list these properties that are found directly on the Array
object:
Array.length
Array.constructor
Array.prototype
Array.isArray
Array.of
Array.observe
Array.from
Array.unobserve
Upvotes: 0
Views: 349
Reputation: 665276
You must be on Firefox. It does implement a non-standard extension of the Array
constructor, where generics function are available as static methods on Array
itself. They are own properties, with the same names as those on Array.prototype
but different values. They are not present in other browsers and won't be in future Firefoxes either.
Upvotes: 1
Reputation: 44088
It is functioning correctly.
Object.getOwnPropertyNames() returns an array whose elements are strings corresponding to the enumerable and non-enumerable properties found directly upon obj....
var propertiesOfArray = Object.getOwnPropertyNames(Array);
console.log(propertiesOfArray);
var propertiesOfArrayPrototype = Object.getOwnPropertyNames(Array.prototype);
console.log(propertiesOfArrayPrototype);
If the properties of Array.prototype is what you want, then don't use Array, use Array.prototype. See update. And the accepted answer here.
Upvotes: 1