Author: Dflying Chen ( http://dflying.cnblogs.com/ )
JavaScript is a very powerful Object Based language, but there are still some deficiencies in its support for Object Oriented. The class library built is also relatively simple and even lacks all commonly used functions. ASP.NET Atlas extends JavaScript at runtime, greatly enhances its object-oriented support capabilities, and extends some commonly used operations during development.
I referred to the Atlas.js file and concluded that Atlas has the following extensions to JavaScript. There are some omissions or errors in some places, please forgive me and correct me.
String object extension
String String.ltrim()
Removes all spaces at the beginning of the original String and returns a new String object.
String String.rtrim()
Removes all spaces at the end of the original String and returns a new String object.
String String.trim()
Removes all spaces at the beginning and end of the original String and returns a new String object.
Boolean String.endsWidth(strEnd)
Whether this String ends with the passed in String.
Boolean String.startsWith(strStart)
Whether this String starts with the passed in String.
String String.format(args1,args2,.)
Similar to String.Format() in C#, {n} in the manipulated String will be replaced by the corresponding nth parameter and a new String object will be returned.
String String.removeSpaces()
Removes all spaces from the original String and returns a new String object.
String String.removeExtraSpaces()
Replace consecutive spaces in the original String with single spaces (including carriage returns) and return a new String object.
String String.removeSpaceDelimitedString(str)
Removes the specified words (text fragments separated by spaces) from the original String and returns a new String object. This method can be used when deleting a class name that contains DOM elements with multiple class names.
Extensions of Array objects
void Array.queue(objValue) and void Array.add(objValue)
Inserts the specified objValue into the end of this Array.
void Array.addRange(rangeArray)
Add the specified rangeArray to the end of the Array.
Boolean Array.contains(objValue) and Boolean Array.exists(objValue)
Returns a Boolean value representing whether the Array contains the objValue item.
Array Array.clone()
Returns a shallow copy of this Array.
void Array.insert(index, objValue)
Insert the specified objValue into the index position of the Array.
ObjectArray.dequeue()
Removes and returns the first entry in this Array.
Object Array.removeAt(index)
Removes and returns the entry at the specified index in this Array.
Boolean Array.remove(objValue)
Removes the specified objValue entry from the Array and returns a Boolean value indicating whether the entry exists and was successfully removed.
Array Array.parse(string)
Parse the incoming Array represented by string into an Array.
void Array.clear()
Clear all entries in this Array.
Integer Array.get_length()
Returns the number of entries in this Array, equivalent to Array.length.
Object Array.getItem(index)
Returns the entry at the specified index in this Array.
Extension of Date object
String Date.toFormattedString(stringFormat)
Format and output the Date object according to the input stringFormat (there are too many format strings... I am too lazy to write them. If you need them, just look at lines 748-871 in Atlas.js).
Extension of Number object
Number Number.parse(string)
Try to parse the incoming string as Number.
String Number.toFormattedString(stringFormat)
Format and output the Number object according to the input stringFormat (the format string is still too much... too lazy to write it, if you need it, just look at lines 935-1024 in Atlas.js).
The Sys.StringBuilder class
is similar to StringBuilder in C#:
var sb = new Sys.StringBuilder();
sb.append("<div>");
sb.appendLine("a line of text");
sb.append("</div>");
someDOMElem.innerHTML = sb.toString();
Object-oriented support defines base classes that can be inherited from
BaseClass = function()
{
// object
}
BaseClass.registerClass("BaseClass");
Inherited classDerivedClass
= function()
{
// Call base constructors
// The 2nd argument is an array you can use to pass arguments
DerivedClass.intializeBase(this,arguments);
}
DerivedClass.registerClass("DerivedClass","BaseClass");
Multiple
inheritanceMultipleInherit= function()
{
MultipleInherit.intializeBase(this,arguments); // bootstrap
// object
}
MultipleInherit.registerClass("MultipleInherit",["BaseClass", "DerivedClass"]);
Define methods that can be overridden
BaseClass = function()
{
// object
this.initialize = function()
{
}
BaseClass.registerBaseMethod(this,"initialize");
}
BaseClass.registerClass("BaseClass");
Call the overridden method of the base class
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"]);
NamespaceregisterNamespace
("Web.Utility");
// Implement Web Utility
registerNamespace("Web.Performance");
// Implement Performance
Define the Enum type var theEnum = Type.createEnum("name1","name2");
for (var strItems in theEnum.getValues())
{
}
Define Flag type
var theFlags = Type.createFlags("name1",value1,"name2",value2,);