本文為翻譯,英文原版的Cheat Sheet(PDF版本)在此下載:http://aspnetresources.com/downloads/ms_ajax_library_cheat_sheets1.zip
原作著作權聲明:
Copyright (c) 2004-2006, Milan Negovan http://www.AspNetResources.comAll rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
註:標註有[S]的為靜態方法,無須執行個體化對象即可使用。
String.endsWith (suffix)
判斷該String是否以指定的尾碼結束。
var isTxt = myString.endsWith ("some_file.txt", ".txt");
// isTxt = true
[S] String.format (format, args)
將該String中的各個格式化項用相應的參數值替代。args可以為單一的Object,或是一個包含多個項的Array。
var user = {
FirstName: 'John',
LastName : 'Doe',
DOB: new Date (1975, 1, 17) };
var label = String.format ("User name: {0} {1}, born {2:d}",
user.FirstName, user.LastName, user.DOB));
// label = "User name: John Doe, born 02/17/1975"
[S] String.localeFormat (format, args)
功能與String.format (format, args)類似,不過格式化時與地區設定相關。
String.startsWith (prefix)
判斷該String是否以指定的首碼開始。請參考String.endsWith (suffix)。
String.trim ()
返回一個原String的拷貝,但將原String開頭和結尾部分的所有空白字元(例如空格或Tab)都移除。
var myString = " A string ";
myString = myString.trim();
// myString = "A string"
String.trimEnd ()
返回一個原String的拷貝,但將原String結尾部分的所有空白字元(例如空格或Tab)都移除。
var myString = "A string ";
myString = myString.trim();
// myString = "A string"
String.trimStart ()
返回一個原String的拷貝,但將原String開頭部分的所有空白字元(例如空格或Tab)都移除。
var myString = " A string";
myString = myString.trim();
// myString = "A string"
[S] Object.getType (instance)
返回指定對象的類型,請參考Object.getTypeName (instance)。
[S] Object.getTypeName (instance)
返回一個表示對象在運行時的完全限定類型的字串。
Type.registerNamespace("Samples");
// Define and register a Samples.Rectangle class.
Samples.Rectangle = function(width, height) {
this._width = width;
this._height = height;
}
Samples.Rectangle.registerClass("Samples.Rectangle");
var a = new Samples.Rectangle(200, 100);
var name = Object.getTypeName(a);
var type = Object.getType (a);
Sys.Debug.trace ("The type name of object \"a\" is: " + name);
Sys.Debug.traceDump (type);
/* The result is:
The type name of object "a" is: Samples.Rectangle
traceDump {Function}
prototype {Samples.Rectangle}
__typeName: Samples.Rectangle
__class: true
*/