zoukankan      html  css  js  c++  java
  • [转]Ajax注册命令空间,类,继承类实例

    <%@ 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>
  • 相关阅读:
    我的专业知识博客宗旨
    数理统计与Matlab: 第3章 假设检验
    数理统计与Matlab: 第1章 数理统计基本概念
    线性代数:第一章 多项式2
    LaTeX科技排版入门简介[Z]
    ISIGHT 5.0 components guide
    用MATLAB优化工具箱解线性规划
    7.忙里偷闲聚众奔庆典 创建型模式总结 1
    9.嫁接品种火爆搞科研 适配器模式
    11.明月如何代表我的心 装饰模式
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2464731.html
Copyright © 2011-2022 走看看