Understanding the .constructor property on JavaScript Objects

Share this video with your friends

Send Tweet

Constructor functions hold an interesting purpose in JavaScript. Unlike in classical languages, they do not always mean created by. In this lesson we’ll use the new keyword to make a constructor call and work with the .constructor property.

Juan Jose
Juan Jose
~ 6 years ago

Hi , In the last code, the last line console.log(a.constructor === Object ) // true should be // false. Amazing video!.

Brendan Whiting
Brendan Whiting
~ 6 years ago

I don't understand where it says that console.log(Foo.prototype.constructor) prints [λ: Foo]. I'm using this playground and it prints function Foo() {}. Where does that lamdba symbol come from?

Jake
Jake
~ 6 years ago

Don't understand...

David Choi
David Choi
~ 6 years ago

Tyler your last example uses Object.defineProperty to reset Foo.prototype's constructor to an anonymous object. And yet when you later call console.log(a.constructor === Foo) it returns true. Why is it Foo and not Object if I created an anonymous object?