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.