每次面试都要从新巩固下这个知识点,决定仍是本身概括下面试
首先贴个《Javascript高级程序设计》的图函数
1、知识点:this
1.普通对象与函数对象spa
var o1 = {}; var o2 =new Object(); var o3 = new f1(); function f1(){}; var f2 = function(){}; var f3 = new Function('str','console.log(str)'); console.log(typeof Object); //function console.log(typeof Function); //function console.log(typeof f1); //function console.log(typeof f2); //function console.log(typeof f3); //function console.log(typeof o1); //object console.log(typeof o2); //object console.log(typeof o3); //object
2.实例的构造函数属性(constructor)指向构造函数。prototype
console.log(person1.constructor == Person); //true
3.每一个对象都有 __proto__ 属性,但只有函数对象才有 prototype 属性
设计
4.原型对象就是 Person.prototype 指针
Person.prototype = { name: 'Zaxlct', age: 28, job: 'Software Engineer', sayName: function() { alert(this.name); } }
在默认状况下,全部的原型对象都会自动得到一个 constructor
(构造函数)属性,这个属性(是一个指针)指向 prototype
属性所在的函数(Person)code
5.这个链接存在于实例(person1
)与构造函数(Person
)的原型对象(Person.prototype
)之间,而不是存在于实例(person1
)与构造函数(Person
)之间。对象
person1.constructor == Person Person.prototype.constructor == Person
person1.__proto__ == Person.prototype
2、划重点:blog
person1.__proto__
是什么?Person.__proto__
是什么?Person.prototype.__proto__
是什么?Object.__proto__
是什么?Object.prototype__proto__
是什么?答案:
第一题:
由于 person1.__proto__ === person1 的构造函数.prototype
由于 person1的构造函数 === Person
因此 person1.__proto__ === Person.prototype
第二题:
由于 Person.__proto__ === Person的构造函数.prototype
由于 Person的构造函数 === Function
因此 Person.__proto__ === Function.prototype
第三题:
Person.prototype
是一个普通对象,咱们无需关注它有哪些属性,只要记住它是一个普通对象。
由于一个普通对象的构造函数 === Object
因此 Person.prototype.__proto__ === Object.prototype
第四题,参照第二题,由于 Person 和 Object 同样都是构造函数
第五题:
Object.prototype
对象也有proto属性,但它比较特殊,为 null 。由于 null 处于原型链的顶端,这个只能记住。
Object.prototype.__proto__ === null