<HTML>
<HEAD>
<TITLE> Public Method </TITLE>
<script>
//通过原型方式创建对象的get,set方法
function User(username,age)
{
this.username = username;
this.age = age;
}
User.prototype.getUsername = function()
{
return this.username;
}
User.prototype.setUsername = function(username)
{
this.username = username;
}
User.prototype.getAge = function()
{
return this.age;
}
User.prototype.setAge = function(age)
{
this.age = age;
}
var me = new User("zdw",22);
alert(me.getUsername() + "\n" + me.getAge());
me.setUsername("admin");
me.setAge(99);
alert(me.getUsername() + "\n" + me.getAge());
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
<HEAD>
<TITLE> Public Method </TITLE>
<script>
//通过原型方式创建对象的get,set方法
function User(username,age)
{
this.username = username;
this.age = age;
}
User.prototype.getUsername = function()
{
return this.username;
}
User.prototype.setUsername = function(username)
{
this.username = username;
}
User.prototype.getAge = function()
{
return this.age;
}
User.prototype.setAge = function(age)
{
this.age = age;
}
var me = new User("zdw",22);
alert(me.getUsername() + "\n" + me.getAge());
me.setUsername("admin");
me.setAge(99);
alert(me.getUsername() + "\n" + me.getAge());
</script>
</HEAD>
<BODY>
</BODY>
</HTML>