简体   繁体   中英

Why o.prototype.isPrototypeof is not a function, my javascript throws an exception

I tried a small code piece:

function o(){};
var Derived = function () {}
Derived.prototype = o;
var o2 = new Derived();
console.log(o.prototype.isPrototypeof(o2));

The last line throws an exception, saying that:

console.log(o.prototype.isPrototypeof(o2));
                    ^
TypeError: o.prototype.isPrototypeof is not a function

This is weird to me, why o doesn't have prototype property? when defining a function/new object, does the name bind to a prototype property automatically?

You can usually depend on Javascript methods and functions being camel-cased, and this is no exception.

The method is .isPrototypeOf() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM