亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JavaScript使用prototype定義對象類型(轉)[

 更新時間:2006年12月22日 00:00:00   作者:  
From: JavaEye.com

prototype提供了一套JavaScript面向對象基礎設施,我們可以使用它來進行面向對象編程,定義對象類型方式如下:
var Person = Class.create();
Person.prototype = {
 initialize : function(name, age) {
 this.name = name;
 this.age = age;
 },
 toString : function() {
 document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age);
 }
}

先使用Class.create()來創(chuàng)建一個對象類型,然后定義該對象類型,注意initialize方法是Person的構造器,完整的HTML如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Object</title>
<script type="text/javascript" src="prototype.js"></script>
</head>
<body>
<script type="text/javascript">

var Person = Class.create();
Person.prototype = {
 initialize : function(name, age) {
 this.name = name;
 this.age = age;
 },
 toString : function() {
 document.writeln("[name]:"+this.name+"<br>"+"[age]:"+this.age);
 }
}

var person = new Person("robbin",30);
person.toString();
</script>
</body>
</html>

相關文章

最新評論