/*1.公有方法是可以在类的外部被调用的,2.但是它不可以访问类的私有属性。3.公有方法必须在类的内部或者外部通过类的prototype属性添加。*/varperson=function(){varage=22;functionshowName(){console.log(this.name)};this.show=function(){console.log(this.name);showName();}}person.prototype.setname=function(str){name=str;}varp1=newperson();p1.setname("大宝");p1.show();console.log(p1.age);//undefined为什么this.show方法下面的this.name为undefiend,而showName方法下的this.name为大宝?
相关分类