Sam Selikoff
Sam Selikoff

Reputation: 12694

Can I view properties stored on a function in Chrome's console?

For example, if I do this in the the console

var Person = function(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}

Person.species = 'homo sapien';

then I type Person, I just see the function; but if I type Person.species I get back 'homo sapien'. I'd like to be able to see all properties that are stored on a function in the console. Is this possible?

Also, does anybody know of a good resource for explaining the mechanics behind what's happening here? I'm struggling with what it means for Person to be both a function and an object. Is the function being stored on some property of the Person object?

Upvotes: 0

Views: 50

Answers (1)

Felix Kling
Felix Kling

Reputation: 816462

Use console.dir:

console.dir(Person);

I'm struggling with what it means for Person to be both a function and an object. Is the function being stored on some property of the Person object?

No. Every function is an object in JavaScript. They are just special objects because they are callable. Just like arrays are objects and also have some special internal behavior.

Upvotes: 5

Related Questions