<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Client Type System</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script language="javascript" type="text/javascript"> Type.registerNamespace("AspNetAjaxOverView");//定義一個命名空間 //定義一個Person類,及其建構函式 AspNetAjaxOverView.Person = function(firstName, lastName) { //一般有_都是私人變數 this._firstName = firstName; this._lastName = lastName; } //定義Person類的方法,使用的是prototype來定義的 AspNetAjaxOverView.Person.prototype = { get_firstName : function() { return this._firstName; }, get_lastName : function() { return this._lastName; }, toString : function() { return String.format("Hello, I'm {0} {1}.", this.get_firstName(), this.get_lastName()); } } //註冊剛定義好的類 AspNetAjaxOverView.Person.registerClass("AspNetAjaxOverView.Person"); AspNetAjaxOverView.Employee = function(firstName, lastName, title) { AspNetAjaxOverView.Employee.initializeBase(this, [firstName, lastName]); this._title = title; } AspNetAjaxOverView.Employee.prototype = { get_title : function() { return this._title; }, toString : function() { return AspNetAjaxOverView.Employee.callBaseMethod(this, "toString") + " My title is '" + this.get_title() + "'."; } } //註冊Employee的類繼承Person AspNetAjaxOverView.Employee.registerClass("AspNetAjaxOverView.Employee", AspNetAjaxOverView.Person); </script> //這會自動調用其toString()函數 <input type="button" value="Bill Gates" onclick="alert(new AspNetAjaxOverView.Employee('Bill', 'Gates', 'Chair man'));" /> <input type="button" value="Steve Ballmer" onclick="alert(new AspNetAjaxOverView.Employee('Steve', 'Ballmer', 'CEO'));" /> </form></body></html>