主要用于判断对象类型
console.log(typeof null) //object console.log(typeof undefined) //undefined console.log(typeof [1,2,3]) //object console.log(typeof boolean) //function console.log(typeof 1) //number console.log(typeof '1') //string console.log(typeof string) //function console.log(typeof boolean) //undefined console.log(typeof true) //boolean console.lig(typeof symbol) //symbol console.log(typeof function) //function
类型有:
1.object
2.function
3.number
4.string
5.boolean
6.undefined
7.symbol =>一种标识唯一性的id
注意:每个symbol属性都是唯一的,任意两个symbol都不相等
instanceof 运算符用于检测构造函数的 prototype
属性是否出现在某个实例对象的原型链上。
右边必须为一个对象
console.log(typeof null) //object console.log(typeof undefined) //undefined console.log(typeof [1,2,3]) //object console.log(typeof boolean) //function console.log(typeof 1) //number console.log(typeof '1') //string console.log(typeof string) //function console.log(typeof boolean) //undefined console.log(typeof true) //boolean console.lig(typeof symbol) //symbol console.log(typeof function) //function
注意:每个函数的原型链上都有原型,再上面都有对象
prototype
只要创建一个新的函数,就会为该函数创建一个prototype属性.该属性指向函数的原型对象.所有原型对象都会自动获得一个constructor构造函数属性,该属性指向prototype属性所在函数的指针.
__proto__
隐式原型指向创建这个对象的函数的prototype.
object.peototype.__proto__ == null
注意:通过function.prototype.bind方法构造出来的函数没有prototype属性。
function p(){} let p1 = new p(); p1.__proto__ === p.prototype //true p.prototype // {constructor: ƒ} p.prototype.constructor === p //true p.__proto__ === function.prototype //true
1.对象只有__proto__
属性,这个属性是指向他的构造函数的prototype属性
function b(b){ this.b = b; } var b = new b('seanxiao') console.log(b)
b对象的属性是__proto__
,指向构造函数b的prototype
,b.protptype.__proto__
指向object.prototype
object.protptype.__protp__
是null
而则一层一层的链接 关系就是原型链。
如对本文有疑问, 点击进行留言回复!!
2016年信息安全工程师综合知识第11-15题解析【建群网培信息安全工程师】
网友评论