面向对象深入理解2

 1     function createPerson(name,sex) {    //构造函数
 2             this.name=name;             //添加属性
 3             this.sex=sex;
 4      }
 5 
 6      createPerson.prototype.showName=function () {   //createPerson的原型的方法
 7            alert(this.name);
 8      };
 9      createPerson.prototype.showSex=function () {
10           alert(this.sex);
11      }
12 
13      var p1=new createPerson('ming','man');
14          p1.showName();
15          p1.showSex();
16      var p2=new createPerson('xiao','woman');
17          p2.showName();
18          p2.showSex();
19       alert(p1.showName=p2.showSex);
原文地址:https://www.cnblogs.com/deveil/p/6264157.html