クラスを作成する

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="css/main.css" type="text/css" media="all">
<script type="text/javascript" src="js/prototype.js" charset="shift_jis"></script>
<script type="text/javascript"><!--
Event.observe(window, "load", function(){
var iPod = Class.create({
initialize : function(name, HDDsize){
this.name = name; // iPod Name
this.size = HDDsize + "GB"; // HDD Size
},
printName : function(obj){
obj.innerHTML = this.name+" ( "+this.size+" )";
}
});
var myPod1 = new iPod("iPod nano", "4");
var myPod2 = new iPod("iPod touch", "16");
myPod1.printName($("result1"));
myPod2.printName($("result2"));
}, false);
// --></script>
</head>
<body>
<h1>クラスを作成する</h1>
<div id="result1">...</div>
<div id="result2">...</div>
</body>
</html>
サンプルを実行
[戻る]
prototype.jsパーフェクトリファレンス説明などは本書を参考にしてください。