• ASP.NET AJAX 创建类


    <%@ Page Language="C#" %>
    
    <!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>Classes</title>
        <script type="text/javascript">
            function pageLoad(sender, args) {
                Type.registerNamespace('Wrox.AspAjax.Samples.Album');
    
                Wrox.AspAjax.Samples.Album = function (title, artist) {
                    this._title = title;
                    this._artist = artist;
                }
    
                Wrox.AspAjax.Samples.Album.prototype = {
                    get_title: function () {
                        return this._title;
                    },
                    get_artist: function () {
                        return this._artist;
                    }
                }
    
                Wrox.AspAjax.Samples.Album.registerClass
                    ("Wrox.AspAjax.Samples.Album");
    
                var anAlbum = new Wrox.AspAjax.Samples.Album("Lost Highway", "Bon Jovi");
    
                alert(anAlbum.get_title());
                alert(Type.isNamespace(Wrox.AspAjax.Samples.Album));
                alert(Type.isClass(Wrox.AspAjax.Samples.Album));
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        </div>
        </form>
    </body>
    </html>

    类型继承:

    <%@ Page Language="C#" %>
    
    <!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>Classes</title>
        <script type="text/javascript">
            function pageLoad(sender, args) {
                Type.registerNamespace("Wrox.AspAjax.Samples.Album");
    
                Wrox.AspAjax.Samples.Album = function (title, artist) {
                    this._title = title;
                    this._artist = artist;
                }
    
                Wrox.AspAjax.Samples.Album.prototype = {
                    get_title: function () {
                        return this._title;
                    },
                    get_artist: function () {
                        return this._artist;
                    }
                }
    
                Wrox.AspAjax.Samples.Album.registerClass('Wrox.AspAjax.Samples.Album');
    
                Wrox.AspAjax.Samples.TributeAlbum = function (title, artist, tributeArtist) {
                    Wrox.AspAjax.Samples.TributeAlbum.initializeBase(this, [title, artist]);
                    this._tributeArtist = tributeArtist;
                }
                Wrox.AspAjax.Samples.TributeAlbum.prototype = {
                    get_tributeArtist: function () {
                        return this._tributeArtist;
                    },
                    set_tributeArtist: function (tributeArtist) {
                        this._tributeArtist = tributeArtist;
                    },
                    get_artist: function () {
                        return ("TRIBUTE:" +
                            Wrox.AspAjax.Samples.TributeAlbum.callBaseMethod(this,
                                "get_artist"));
                    }
                }
    
                Wrox.AspAjax.Samples.TributeAlbum.registerClass(
                    'Wrox.AspAjax.Samples.TributeAlbum',
                    Wrox.AspAjax.Samples.Album);
    
                var anotherAlbum =
                    new Wrox.AspAjax.Samples.TributeAlbum("We're a Happy Family",
                    "Various Artists", "Ramones");
                alert(anotherAlbum.get_title());
                alert(anotherAlbum.get_tributeArtist());
    
                var anAlbum = new Wrox.AspAjax.Samples.Album("Lost Highway", "Bon Jovi");
    
                if (Wrox.AspAjax.Samples.TributeAlbum.isInstanceOfType(anAlbum) == false) {
                    alert("anAlbum is not a TributelAlbum");
                }
    
                if (Wrox.AspAjax.Samples.TributeAlbum.isInstanceOfType(anotherAlbum) == true) {
                    alert("anotherAlbum is a TributeAlbum");
                }
    
                if (Wrox.AspAjax.Samples.TributeAlbum.inheritsFrom(Wrox.AspAjax.Samples.Album)) {
                    alert("TributeAlbum inherits from Album");
                }
    
                if (Wrox.AspAjax.Samples.Album.inheritsFrom(Wrox.AspAjax.Samples.TributeAlbum) == false) {
                    alert("Album does not inherit from TributeAlbum");
                }
    
                var typeString = "Wrox.AspAjax.Samples.TributeAlbum";
                var typeCheck = Type.parse(typeString);
                alert(Type.isClass(typeCheck));
                alert(Type.isClass(Wrox.AspAjax.Samples.TributeAlbum));
                alert(typeCheck);
                if (Type.isClass(typeCheck)) {
                    alert(typeCheck.getBaseType().getName());
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        </div>
        </form>
    </body>
    </html>
  • 相关阅读:
    精选 TOP 面试题
    leecode100热题 HOT 100(2)
    leecode100热题 HOT 100
    leetcode题库
    LeetCode All in One 题目讲解汇总(持续更新中...)
    LVS负载均衡(LVS简介、三种工作模式、十种调度算法)
    Smart/400开发上手3: 练习实践
    Smart/400开发上手2: COBOL批处理程序处理过程
    Smart/400开发上手1:入门
    一步步Cobol 400上手自学入门教程06
  • 原文地址:https://www.cnblogs.com/hellolong/p/3995212.html
Copyright © 2020-2023  润新知