-1

I've been using Object.getOwnPropertyNames for a while. This is my code:

var ObjectAdditions = {
    deepFreeze: function(o) {//code},
    extendToArray: function(object) {//code}
};
var properties = Object.getOwnPropertyNames(ObjectAdditions);

This is what properties came up as:

["deepFreeze", "extendToArray"]

Unfortunately I also expected attributes like "prototype" and "constructor" to come up. How can I do this?

norbitrial
  • 14,716
  • 7
  • 32
  • 59
Sci Pred
  • 33
  • 4
  • Does this answer your question? [List Down All Prototype Properties of an Javascript Object](https://stackoverflow.com/questions/30158515/list-down-all-prototype-properties-of-an-javascript-object) – norbitrial Mar 23 '20 at 09:25
  • I don't mean the properties of the prototype, I mean the prototype itself – Sci Pred Mar 23 '20 at 10:02

1 Answers1

0

Your ObjectAdditions is just a simple object with deepFreeze and extendToArray as properties. It is not a class.

Object.getOwnPropertyNames with classes looks like this:

class MyClass {
  // the cunstructer doesn't apper anywhere else than as MyClass() itself. It is only callable with "new".
  constructor() {
    // this will be added as a property to the instance
    this.myInstanceAttribute = null;
  }
  // this will be added as a property to the class
  static myStaticFunction() {}
  // this will be added to the prototype
  myInstanceFunction() {}
}
MyClass.myStaticAttribute = null;

// shows the class prototype and name, the statics and length from the constructor-function (numer of expected parameters) 
console.log('class', Object.getOwnPropertyNames( MyClass ));

// only the added "myInstanceAttribute"
console.log('instance', Object.getOwnPropertyNames( new MyClass() ));
Niklas E.
  • 1,848
  • 4
  • 13
  • 25