javascript创建对象的志向方法

javascript创建对象的理想方法

建议混合使用构造函数+ 原型的方式

代码如下:

function Person(Name,Age){
    this.name=Name;
    this.age=Age;
    this.action=new Array("work","sleep");
}
   
    Person.prototype.walk=function(){
         alert(this.name+" is walking");
        }
   var you=new Person("you",24);
    var me=new Person("me",100);
    you.action.push("eat");
    alert(you.action);
    you.walk();
    alert(me.action);

 

具体原因度神,谷姐啦!呵呵!