Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Javascript Prototype


m being puzzled by JS prototype.

var test = function() {}; 

var result_one = typeof test; //Function
var result_two = (test.__proto__ === Function.prototype); // true
var result_three = test.constructor; //Function () { [native code] }
var result_four = test instanceof Function; //true
var result_five = test.prototype; //Object {}
var result_six = Function.prototype; // Function Empty() {}

As we declare the test function, test become a instance of the constructor, Function. As Douglas Crockford said, except String, Number, Boolean, null and undefined. Anything else in JS are Object.

So, Function is also Object. But as test is a function, instance of Function and Function.prototype is an Empty function, how could it has a prototype of Object ?

1 Answer

I just found out this:

Function.prototype.__proto__ === Object.prototype; //true

I think this might help understand the Prototype in JS, but m still confused, what does the Function Empty () {} exists for?