Asp.net Ajax [client 1] syntax

Source: Internet
Author: User

Learning Asp.net Ajax class definition and inheritance syntax

Syntax. js

/// <Reference name = "microsoftajax. js"/>
Type. registernamespace ("Syntax ");

Syntax. machinestate = function (){}

Syntax. machinestate. Prototype = {
Stopped: 0,
Running: 1
}

Syntax. machinestate. registerenum ("syntax. machinestate ");

Syntax. imachine = function ()
{}

Syntax. imachine. Prototype = {
Get_currentstate: function (){},
Startup: function (){},
Shutdown: function (){}
}

Syntax. imachine. registerinterface ("syntax. imachine ");

Syntax. machinebase = function (typestr)
{
This. _ typestr = typestr;
This. _ currentstate = syntax. machinestate. stopped;

}

Syntax. machinebase. Prototype = {
Get_typestr: function () {return this. _ typestr ;},
Get_currentstate: function () {return this. _ currentstate ;},
Startup: function () {This. _ currentstate = syntax. machinestate. Running ;},
Shutdown: function () {This. _ currentstate = syntax. machinestate. Stopped ;}
}

Syntax. machinebase. registerclass ("syntax. machinebase", null, syntax. imachine );

Syntax. Engine = function (typestr, maxpower)
{
Syntax. Engine. initializebase (this, [typestr]);
This. _ maxpower = maxpower;
}

Syntax. Engine. Prototype = {
Get_maxpower: function () {return this. _ maxpower ;},
Startup: function () {syntax. Engine. callbasemethod (this, "Startup ");},
Shutdown: function () {syntax. Engine. callbasemethod (this, "shutdown ");}
}

Syntax. Engine. registerclass ("syntax. Engine", syntax. machinebase );

If (typeof (sys )! = Undefined) SYS. application. policyscriptloaded ();

Page Section

<Script language = "JavaScript" type = "text/JavaScript">
Function pageload ()
{
VaR engineobj = new syntax. Engine ("DK-500", 523 );
Engineobj. startup ();
SYS. Debug. tracedump (engineobj, "engineobj ");
SYS. Debug. Trace (string. Format ("syntax. Engine inherits from syntax. machinebase? : {0} ", syntax. Engine. inheritsfrom (syntax. machinebase )));
SYS. Debug. Trace (string. Format ("syntax. Engine implements syntax. imachine? : {0} ", syntax. Engine. implementsinterface (syntax. imachine )));

}

</SCRIPT>

</Div>
<Fieldset Title = "output" style = "width: 500px">
<Legend> output result </legend>
<Textarea id = "traceconsole" Cols = "5" style = "width: 495px" readonly = "readonly"> </textarea>
</Fieldset>

Output

Experience:

1. Call the methods of the base class from the derived class, such as

Syntax. Engine. Prototype = {
Get_maxpower: function () {return this. _ maxpower ;},
Startup: function () {syntax. Engine. callbasemethod (this, "Startup ");},
Shutdown: function () {syntax. Engine. callbasemethod (this, "shutdown ");}
}

That is, the callbasemethod method is used, which is similar to the call method in general JavaScript.

2. When the class contains a constructor with parameters, the type. registerclass registration class will report an error. You can only use the class name. registerclass to register the class.

Related Article

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.