/    Sign up×
Community /Pin to ProfileBookmark

Javascript basics question

function Hero() { }

var hero = new Hero();
console.log(hero.constructor); //Hero()
console.log(hero.constructor.prototype); // Object{}
—————————————————
hero.constructor === hero.constructor.prototype.constructor; //true

Can someone explain how the last line evaluated to true?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 19.2011 — Simple. Both expressions return the function itself
<i>
</i>alert(hero.constructor) // function Hero(){}
alert(hero.constructor.prototype.constructor) // function Hero(){}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@rnd_meMay 19.2011 — basically, if not specified, the prototype of a custom object is simply an empty instantiation of that object.

hero.constructor is a function, Hero.

Hero.prototype is an object, blank but derived from Hero.

Hero.prototype.constructor is the function that made the prototype object, Hero.
×

Success!

Help @JNinja spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...