Ajax註冊命令空間,類,繼承類執行個體

來源:互聯網
上載者:User
<%@ 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>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.