在学习过程中对js的constructor的作用产生了疑问。下面是学习的资料进行梳理function Person(area){ this.type = person; this.area = area;}Person.prototype.sayArea = function ...
在学习过程中对js的constructor的作用产生了疑问。下面是学习的资料进行梳理
function Person(area){ this.type = 'person'; this.area = area;}Person.prototype.sayArea = function(){ console.log(this.area);}var Father = function(age){ this.age = age;} Father.prototype = new Person('Beijin');console.log(Person.prototype.constructor) //function person()console.log(Father.prototype.constructor); //function person()Father.prototype.constructor = Father; //修正console.log(Father.prototype.constructor); //function father()var one = new Father(25);
二、修正时显而易见,one.constructor = Father.prototype.constructor = function Father();三、作用
原标题:js中constructor的作用
关键词:JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。