欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript使用prototype定義對(duì)象類型(轉(zhuǎn))[

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

prototype提供了一套JavaScript面向?qū)ο蠡A(chǔ)設(shè)施,我們可以使用它來進(jìn)行面向?qū)ο缶幊?,定義對(duì)象類型方式如下:
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)建一個(gè)對(duì)象類型,然后定義該對(duì)象類型,注意initialize方法是Person的構(gòu)造器,完整的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>

相關(guān)文章

最新評(píng)論