再谈 object instanceof constructor

来源:互联网 发布:假币在淘宝里叫什么 编辑:程序博客网 时间:2024/05/18 00:39

MDN对object instanceof constructor的说明,instanceof 用来判断constructor.prototype是否存在于object原型链中。

下面给个例子

var str = new String()var str2 = "456"console.log(typeof str)//objectconsole.log(typeof str2)//string//object instanceof constructor//instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链上。console.log( str instanceof String )//trueconsole.log( str2 instanceof String )//falseconsole.log(str.__proto__)console.log( String.prototype )console.log( String.prototype.__proto__ )console.log( Object.prototype.__proto__)

console.log( String.prototype )输出



对于str它的原型链是这样的


原创粉丝点击