JAVSCRIPT対象入門例

750 ワード

<html >
<head>
<title></title>

</head>

<body>
<script type="text/javascript">
/*
person class
*/
function Person(name){
this.name = name;
}

Person.prototype ={
getName : function(){
return this.name;
},
setName : function(name){
this.name = name;
},
showName : function(){
alert(this.name);
}

}

var xm = new Person("xiaoming");
xm.showName();
xm.setName("zhangsan");
xm.showName();


/*
extend class(dynamic)
*/
Person.prototype.getGreeting = function(){
return "hello," + this.name;
}

alert(xm.getGreeting());

/*

*/

</script>
</body>
</html>