和普通函数是同样的,只是调用方式是不同,
eg:浏览器
function Person(name,age){ this.name=name; this.age=age; this.say=function(){ return ("i am forever").join(this.age); } }
var person = new Person ("andy",18);//须要使用new关键字来调用 new Person();
Person ("andy",18);//普通函数的调用方式:直接调用 person()
函数
每一个函数(对象)都会有prototype属性,该属相指向的即是原型对象;
Person.prototype.construct===Person //true
prototype等价于__proto__。 __proto__是社区提出来的,因此有些浏览器是不具备该属性的
this
对象的constructor属性用于返回建立该对象的函数,也就是咱们常说的构造函数。
因此原型对象的construct属性指向的是构造函数。
spa