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