Simple Javascript Exted

1384 ワード

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
	<script language="JavaScript" type="text/javascript" src="Prototype.js"></script>
</head>

<body>

<script type="text/javascript">
var Util = {
	version:'1.0'
}

Util.MyObject = Class.create();
Util.MyObject.prototype = {
	id: 'tableId',
	name:'tableName',
	initialize : function(id, name){
		this.id = id;
		this.name = name;
	},
	display : function(){
		alert(this.id + ": "+ this.name);
	}
}
Util.ExtendObject = Class.create();
Util.ExtendObject.prototype = Object.extend(new Util.MyObject(),{
	/*initialize : function(id, name){
		this.id = id;
		this.name = name;
	},
	display : function(){
		alert("extend: "+ this.id + ": "+ this.name);
	},*/
	
	sayHello : function(){
		alert("hello! " + "extend: "+ this.id + ": "+ this.name);
	}
})

try{
	var testObject = new Util.MyObject("testObjectId", "testObjectName");
	testObject.display();
	
	var extendObject = new Util.ExtendObject("extendObjectId","extendObjectName");
	extendObject.display();
	extendObject.sayHello();
}catch(e){
	alert(e.message);
}

</script>

</body>
</html>