Client programming in Ajax Learning

Source: Internet
Author: User

First of all, I declare that many of the content in this article is excerpted from the Internet, mainly to improve my own training websites for the company ..

Client Programming
    • This topic describes Ajax client object-oriented programming.
SYS. Type
  • Type. registernamespace ("namespace name ");
  • Classinstancevar. registerclass ("Class Name", base class (optional), interface (optional, multiple write in sequence ));
  • Typeinstancevar. registerinterface ("Interface Name ");
  • Anamespace. anenum. registerenum ("enumeration name ");
  • Typevar. initializebase (the instance that initializes the base class (usually this), [parameters for passing values to the base class constructor] (optional); (the returned value is the base class instance)
  • Instancevar. callbasemethod (the instance that calls the base class method (usually this), "base class method name", [parameters passed to the base class method] (optional ));
CodeExample

// Register a namespace named "Demo" <br/> type. registernamespace ("Demo"); <br/> // defines the message class constructor in the demo namespace <br/> demo. message = function (content, publishtime) <br/>{< br/> // by default, the following lines are private attributes <br/> This. _ content = content; <br/> This. _ publishtime = publishtime; <br/>}< br/> // defines the message class method in the demo namespace <br/> demo. message. prototype = <br/>{< br/> get_content: function () <br/>{< br/> return this. _ content; <br/>}, <br/> get_pu Blishtime: function () <br/>{< br/> return this. _ publishtime. format ("yyyy-mm-dd hh: mm: SS"); <br/>}, <br/> tostring: function () // override the method of the base class Object <br/>{< br/> return this. get_content () + "" + this. get_publishtime (); <br/>}< br/> // register the message class in the demo namespace. (I do not know why to define the class first and then register it ..) <Br/> demo. message. registerclass ('demo. message '); <br/> // defines the icontent interface in the demo namespace (the interface cannot have constructors) <br/> demo. icontent = function () <br/>{< br/>}< br/> // define the icontent interface method in the demo namespace <br/> demo. icontent. prototype = <br/>{< br/> showcontent: function () <br/>{< br/>}< br/> // register the icontent interface in the demo namespace <br/> demo. icontent. registerinterface ('demo. icontent'); <br/> // define the constructor of the messagewithuserid class in the demo namespace <br/> // me And then let this class inherit from demo. message <br/> // call the base class constructor using initializebase In the constructor <br/> demo. messagewithuserid = function (userid, content, publishtime) <br/>{< br/> demo. messagewithuserid. initializebase (this, [content, publishtime]); <br/> This. _ userid = userid; <br/>}< br/> // define the messagewithuserid class method in the demo namespace <br/> demo. messagewithuserid. prototype = <br/>{< br/> get_userid: function () <br/>{< br/> return this. _ userid; <br />}, <Br/> showcontent: function () <br/>{< br/> return demo. messagewithuserid. callbasemethod (this, 'Get _ content') <br/>}, <br/> // callbasemethod is used to call the method of the base class <br/> tostring: function () <br/>{< br/> return this. get_userid () + "" + demo. messagewithuserid. callbasemethod (this, 'tostring '); <br/>}< br/> // register the messagewithuserid class in the demo namespace <br/> // It inherits from the demo. message class and demo. icontent interface <br/> demo. messagewithuse RID. registerclass ('demo. messagewithuserid ', demo. message, demo. icontent); <br/> // defines the color enumeration in the demo namespace (the enumeration cannot have constructors) <br/> demo. color = function () <br/>{< br/>}< br/> // defines the color enumeration member in the demo namespace <br/> demo. color. prototype = <br/> {<br/> // "0x" indicates hexadecimal, And the eval is converted to an integer in decimal format. <br/> Red: 0xff0000, <br/> Blue: 0x0000ff, <br/> Green: 0x00ff00, <br/> White: 0 xffffff <br/>}< br/> // register the color enumeration in the demo namespace <br/> demo. color. regis Terenum ("demo. color "); <br/> // The sys. application. notifyscriptloaded Method Add call <br/> // we recommend that you include the following sentence at the end of each JS file <br/> // notify scriptmanager that the script has been loaded <br/> If (typeof (sys )! = 'Undefined') SYS. application. policyscriptloaded (); <br/>

Introduction
      VaR testmessage = new demo. Message ('hello', d );
      Alert (testmessage. get_content () + "" + testmessage. get_publishtime ());
      Alert (testmessage );
    • If the above Javascript is defined in a file, you need to introduce the file. For the scriptmanager control, you need to set it as follows:

scripts >
Asp: scriptreference path = " myscript. JS " />
scripts >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.