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

JavaScript使用prototype定義對象類型

 更新時間:2007年02月07日 00:00:00   作者:  
From: JavaEye.com prototype提供了一套JavaScript面向?qū)ο蠡A(chǔ)設(shè)施,我們可以使用它來進(jìn)行面向?qū)ο缶幊?,定義對象類型方式如下: 
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的構(gòu)造器,完整的HTML如下: 
復(fù)制代碼 代碼如下:

<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"></DIV>
<DIV class=code>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);
 }
}</DIV>
<DIV class=code>var person = new Person("robbin",30);
person.toString();
</script>
</body>
</html>

相關(guān)文章

最新評論