创建JavaScript标准对象--面试经常遇到的问题

  1. //用构造函数创建对象,利用原型为函数添加方法
  2. function Person(name,age,sex){
  3. this.Name=name;
  4. this.Age=age;
  5. this.Sex=sex;
  6. }
  7. Person.prototype.play=function(){
  8. return "我是:"+this.Name+",姓名:"+this.Age+",年龄:"+this.Sex+"";
  9. }
  10. Person.prototype.fav=function(food){
  11. return "我爱吃"+food+"";
  12. }
  13. var per=new Person('xiao',12,'nv');
  14. alert(per.play());
  15. alert(per.fav("苹果"));
原文地址:https://www.cnblogs.com/HorseKing/p/4160492.html