Object-oriented in Microsoft Ajax Library (2)

Source: Internet
Author: User

Next http://www.cnblogs.com/Brave-Heart/archive/2008/06/25/1229839.html

Interface
· Constructor throws an exception
· All methods throw an exception
· The registerinterface method is used to register interfaces.
· Interfaces cannot inherit other interfaces
· Definition (similar to definition class)
Mynamespace. imyinterface = function ()
{
Throw error. notimplemented ();
}
Mynamespace. imyinterface. Prototype =
{
Mymethod: function ()
{
Throw error. notimplemented ();
},
......
}
Mynamespace. imyinterface. registerinterface ("mynamespace. imyinterface ");

· Implementation Interface
Use the registerclass method to pass in additional parameter implementation Interfaces
Mynamespace. myclass. registerclass ("mynamespace. myclass", null, mynamespace. imyinterface1, imyinterface2 ,...);
// The second parameter null indicates no parent class

[Code demo ]:

<Asp: scriptmanager id = "scriptmanager1" runat = "server">
</ASP: scriptmanager>


<Script language = "JavaScript" type = "text/JavaScript">

Type. registernamespace ("dongdenamespace ");



Dongdenamespace. worker = function (name)
{
This. _ name = Name? Name: "(unknown )";
This. _ bornyear = 0;
}

Dongdenamespace. Worker. Prototype =
{
Get_name: function ()
{
Return this. _ name;
},


Get_bornyear: function ()
{

Return this. _ bornyear;
},
Set_bornyear: function (value)
{
This. _ bornyear = value;

},


Getage: function ()
{
Return 2008-This. _ bornyear;

},


Getworkerdescript: function ()
{

Return string. Format ("{0} age: {1}, born at: {2}", this. _ name, this. getage (), this. get_bornyear ());
},

// Abstract Method
Getsalary: function ()
{
Throw error. notimplemented ();

}
}


//////////////////////////////////////// //////////
Dongdenamespace. iworker = function ()
{
Throw error. notimplemented ();
}
Dongdenamespace. iworker. Prototype = function ()
{
Getsex: function ()
{
Throw error. notimplemented ();
}


}

Dongdenamespace. iworker. registerinterface ("dongdenamespace. iworker ");
Dongdenamespace. Worker. registerclass ("dongdenamespace. Worker", null, dongdenamespace. iworker );
// Dongdenamespace. Worker. registerclass ("dongdenamespace. Worker ");

VaR newworker = new dongdenamespace. Worker ();

Alert (dongdenamespace. iworker. isimplementedby (newworker); // isimplementedby reflection method,
Determine whether the newworker object has implemented the dongdenamespace. iworker Interface

</SCRIPT>

Enumeration
· Enumeration is called number.
· A major benefit is the competition for strong readability and the discovery of many initial writes Program Indicates that a certain State is represented by numbers 1, 2, 3 .... Code Is not readable and hard to understand
· Each Enumeration type has the tostring and parse methods.
· Definition
Mynamespace. myenum = function ()
{
Throw error. notimplemented ();
}
Mynamespace. myenum. Prototype =
{
Item1: 1,
Item2: 2,
Item3: 3
}
Mynamespace. myenum. registerenum ("mynamespace. myenum", [, true]);

[Code demo]: A simple Column

<Asp: scriptmanager id = "scriptmanager1" runat = "server">
</ASP: scriptmanager>

<Script language = "JavaScript" type = "text/JavaScript">

Type. registernamespace ("mynamespace ");

Mynamespace. myenum = function ()
{
Throw error. notimplemented ();

}
Mynamespace. myenum. Prototype =
{
Item1: "dongde ",
Item2: "Ling ",
Item3: "Mary"
}
Mynamespace. myenum. registerenum ("mynamespace. myenum ");


Alert (mynamespace. myenum. Item1 );
Alert (mynamespace. myenum. tostring (mynamespace. myenum. Item1 ));

</SCRIPT>

Reflection Method

Type. Prototype. getbasetype
Type. Prototype. getinterfaces
Type. Prototype. getname
Type. Prototype. implementsinterface
Type. Prototype. inheritsfrom
Type. Prototype. isimplementedby
Type. Prototype. isinstanceoftype
Type. getrootnamespaces
Type. isclass
Type. isinterface
Type. isnamespace
Type. isenum
Type. isflags
Type. parse
Object. GetType
Object. gettypename

 

 

 

 

 

 

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.