<%@ 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>

 

posted on 2012-04-22 10:44  gzh4455  阅读(294)  评论(0编辑  收藏  举报