- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Inherit1.3.1.aspx.cs" Inherits="Inherit1" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>無標題頁</title>
- <script language="javascript">
- <!--
- //定義一個靜態的方法
- Object.extend = function(destination,source){
- for(property in source){
- destination[property]=source[property];
- }
- }
- //通過Object類爲每個對象添加方法extend
- Object.prototype.extend= function(object){
- return Object.extend.apply(this,[this,object]);
- }
- Function.prototype.inherit= function(object){
- for(var p in object.prototype)
- {
- this.prototype[p]=object.prototype[p];
- }
- }
- //定義一個對象class1
- function class1()
- {
- }
- class1.prototype={
- method:function(){alert("class1");},
- method2:function(){alert("method2 of class1")}
- }
- //定義class2
- function class2()
- {
- }
- // class2.prototype=(new class1()).extend({
- // method:function(){
- // alert("Class2");
- // }
- // });
- //定義class2的對象成員
- class2.inherit(class1);
- class2.prototype.method2=function()
- {
- alert("class2");
- }
- var obj1 = new class1();
- var obj2= new class2();
- obj1.method();
- obj2.method();
- -->
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- </div>
- </form>
- </body>
- </html>