function Person(name,age,job){ this.name = name; this.age = age; this.ob = job;}function Man(name,age,job,mustache){ this.mustache = mustache; Man.prototype = new Person(name,age,job);}var m = new Man('Anthony',27,'PE');m.name;//undefined这里的m.name 是undefined 的,但是可以确定的是在构造函数体内是可以访问构造函数本身的原型的,如下:function Person(name,age,job){ this.name = name; this.age = age; this.ob = job; if(typeof this.sayName != 'undefined'){ Person.prototype.sayName = function(){ alert(this.name) } }}var p = new Person('anthony',29,'PE');p.sayName();//anthony
添加回答
举报
0/150
提交
取消