Author:Dflying Chen (Http://dflying.cnblogs.com/)
JavascriptIs a very powerful object-based (Object BasedBut for (Object Oriented).JavascriptThe built-in class libraries are also relatively simple, and even lack all common functions.ASP. NET AtlasExtended during runtimeJavascriptIt greatly enhances its object-oriented support capabilities and extends some common operations for development.
I have referencedAtlas. jsFile, summed upAtlasPairJavascriptThe following extensions are available. Some omissions or errors may occur. Please forgive me and correct me.
String object extension
-
- String string. ltrim ()
Remove originalStringAll spaces at the beginning, and a newStringObject.
- String string. rtrim ()
Remove originalStringAll spaces at the end, and a newStringObject.
-
- String string. Trim ()
Remove originalStringAll spaces at the beginning and end, and a newStringObject.
-
- Boolean string. endswidth (strend)
TheStringWhether to pass inStringEnd.
-
- Boolean string. startswith (strstart)
TheStringWhether to pass inStringStart.
- String string. Format (args1, args2 ,.)
SimilarC #InString. Format (), OperatedStringIn{N}Will be replaced by the correspondingNAnd return a newStringObject.
-
- String string. removespaces ()
Remove originalStringAnd returns a newStringObject.
-
- String string. removeextraspaces ()
Change the originalStringAnd returns a newStringObject.
- String string. removespacedelimitedstring (STR)
Change the originalStringRemove the specified word (separated by spaces) in and return a newStringObject. This method can be used to delete multipleClassNameDomElementClassName.
Array object extension
-
- Void array. Queue (objvalue)AndVoid array. Add (objvalue)
ObjvalueInsert to thisArray.
-
- Void array. addrange (rangearray)
RangearrayJoin thisArray.
- Boolean array. Contains (objvalue)AndBoolean array. exists (objvalue)
Returns a Boolean value representingArrayInclude or notObjvalueProject.
-
- Array array. Clone ()
ReturnsArray.
-
- Void array. insert (index, objvalue)
ObjvalueInsert to thisArrayOfIndexLocation.
-
- Object array. dequeue ()
Remove and returnArrayThe first entry in.
-
- Object array. removeat (INDEX)
Remove and returnArraySpecified inIndex.
- Boolean array. Remove (objvalue)
Remove thisArraySpecified inObjvalueThe return Boolean value indicates whether the entry exists and is successfully removed.
-
- Array array. parse (string)
TheStringRepresentsArrayResolvedArray.
-
- Void array. Clear ()
ClearArrayAll entries in.
-
- Integer array. get_length ()
ReturnsArrayNumber of entries, equivalentArray. Length.
-
- Object array. getitem (INDEX)
ReturnsArraySpecified inIndex.
Date object extension
- String date. toformattedstring (stringformat)
According to the inputStringformatFormat and outputDateObject (Format StringToo many ...... I am too lazy to write it. You need to read it directly.Atlas. jsMedium748-871All right ).
Number object extension
- Number number. parse (string)
Try to parse the incomingStirngIsNumber.
- String number. toformattedstring (stringformat)
According to the inputStringformatFormat and outputNumberObject (Format StringToo many ...... I am too lazy to write it. You need to read it directly.Atlas. jsMedium935-1024Rows ).
SYS. stringbuilder class
SimilarC #InStringbuilder:
VaR Sb = New SYS. stringbuilder ();
SB. append ( " <Div> " );
SB. appendline ( " A line of text " );
SB. append ( " </Div> " );
Somedomelem. innerhtml = SB. tostring ();
Object-oriented support
Define a base class that can be inherited
Baseclass = Function ()
{
//Object
}
Baseclass. registerclass ( " Baseclass " );
Inheritance class
Derivedclass = Function ()
{
//Call base Constructors
//The 2nd argument is an array you can use to pass arguments
Derivedclass. intializebase (This, Arguments );
}
Derivedclass. registerclass ( " Derivedclass " , " Baseclass " );
Multi-Inheritance
Multipleinherit = Function ()
{
Multipleinherit. intializebase (This, Arguments );//Bootstrap
//Object
}
Multipleinherit. registerclass ( " Multipleinherit " ,[ " Baseclass " , " Derivedclass " ]);
Define writable (Override) Method
Baseclass = Function ()
{
// Object
This . Initialize = Function ()
{
}
Baseclass. registerbasemethod ( This , " Initialize " );
}
Baseclass. registerclass ( " Baseclass " );
Call the base class override method Derivedclass = Function ()
{
Derivedclass. initializebase ( This , Arguments ); // Bootstrap
This . Initialize = Function ()
{
Derivedclass. getbasemethod ( This , " Baseclass " , " Initialize " ). Call ( This );
// To pass arguments to base class:
// . Call (this, args1, args2, args3)
}
}
Derivedclass. registerclass ( " Derivedclass " ,[ " Atlas. bindings. Base " , " Baseclass " ]);
Namespace
Registernamespace ( " Web. Utility " );
// Implement web Utility
Registernamespace ( " Web. Performance " );
// Implement Performance
DefinitionEnumType
VaR Theenum = Type. createenum ( " Name1 " , " Name2 " );
For ( VaR Stritems In Theenum. getvalues ())
{
}
DefinitionFlagType
VaR Theflags = Type. createflags ( " Name1 " , Value1, " Name2 " , Value2 ,);