ajax客户端类型系统简单介绍

来源:互联网 发布:mac pro用什么显示器 编辑:程序博客网 时间:2024/03/29 14:48
看了赵劼老师的深入浅出ajax了解了点javascript仿面向对象的编程

初次接触,根据视频中的讲解,记录下第一部分的基本代码:

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>无标题页</title>
  6. </head>
  7. <body>
  8.     <form id="form1" runat="server">
  9.     <!--这个控件是必须的-->
  10.     <asp:ScriptManager runat="server" ID="scriptManager1">
  11.     </asp:ScriptManager>
  12.     <script language="javascript" type="text/javascript">
  13.     
  14.     //用type类型申明一个命名空间  AjaxNameSpaceTest
  15.     Type.registerNamespace("AjaxNameSpace");
  16.     // 相当于给上面命名空间中添加一个Person类的构造函数
  17.     AjaxNameSpace.Person=function(firstName,lastName){
  18.        //js类型中以 _开头的变量为私有变量
  19.         this._firstName=firstName;
  20.         this._lastName=lastName;
  21.     }
  22.     //添加get set属性,和方法
  23.     AjaxNameSpace.Person.prototype={
  24.         get_firstName:function(){
  25.             return this._firstName;
  26.         },
  27.         set_firstName:function(){
  28.             this._firstName=value;
  29.         },
  30.         get_lastName:function(){
  31.             return this._lastName;
  32.         },
  33.         //toString()方法 这个应该不陌生
  34.         toString:function(){
  35.             return String.format("Hi,I'm {0} {1}.",this.get_firstName(),this.get_lastName());
  36.         }
  37.     }
  38.     //注册类
  39.     AjaxNameSpace.Person.registerClass("AjaxNameSpace.Person");
  40.     
  41.     //再注册一个类 继承上面的AjaxNamespace.Person
  42.     AjaxNameSpace.Employee=function(firstName,lastName,title){
  43.     //调用基类的构造函数
  44.         AjaxNameSpace.Employee.initializeBase(this,[firstName,lastName]);
  45.         this._title=title;
  46.     }
  47.     
  48.     AjaxNameSpace.Employee.prototype={
  49.         get_title:function(){
  50.             return this._titel;
  51.             }
  52.         //重写方法toString
  53.         toString:function(){
  54.              //callBaseMethod()方法 调用基类方法
  55.             return AjaxNameSpace.Employee.callBaseMethod(this,"toString") + "My title is '"+this._title +"'.";
  56.         }
  57.     }
  58.             //注册类并说明继承自那个类
  59.      AjaxNameSpace.Employee.registerClass("AjaxNamespace.Employee",AjaxNameSpace.Person);
  60.     </script>
  61.    <input type="button"  value="Lu Guang" onclick="alert(new AjaxNameSpace.Person('Lu','Guang'));" />
  62.     <input type="button"  value="Huang Yan" onclick="alert(new AjaxNameSpace.Employee('Huang','Yan','Student'));" />
  63.     </form>
  64. </body>
  65. </html>
先记录这些~~