js自定义对象

2016-11-14  本文已影响23人  71150ce14a00

function Person(){

}

var p = new Person(); 

p.age = 23; 

p.name = "zhangsan"; 

p.setName = function(name){

 this.name = name;

 } 

 document.write(p.name+"");

 document.write(p.age+""); 

p.setName("李四"); document.write(p.name+"");

function Student (name,age){

this.name = name;

this.age = age;

this.setName = function(name){

this.name = name;

}

this.getName = function(name){

return this.name;

}

}

var s = new Student("dubo",24);

document.write(s.getName());

上一篇 下一篇

猜你喜欢

热点阅读