JavaScript isPrototypeOf vs instanceof usage
Suppose we have the following:
function Super() {
// init code
}
function Sub() {
Super.call(this);
// other init code
}
Sub.prototype = new Super();
var sub = new Sub();
Then, in some other part of our ocde, we can use either of the following
to check for the relationship:
sub instanceof Super;
or
Super.prototype.isPrototypeOf( sub )
Either way, we need to have both the object (sub), and the parent
constructor (Super). So, is there any reason why you'd use one vs the
other? Is there some other situation where the distinction is more clear?
I've already carefully read 2464426, but didn't find a specific enough
answer.
No comments:
Post a Comment