本文為翻譯,英文原版的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]的為靜態方法,無須執行個體化對象即可使用。
Number.format (format)
用指定的format格式化數字(地區設定無關)。
Number.localeFormat (format)
用指定的format格式化數字(地區設定相關)。
支援的格式
- p:將數字轉為百分比字串(e.g.: -1,234.56 %)
- d:將數字裝化為十進位字串,沒有逗號分隔字元(e.g.: -1234.56)
- c:將數字轉化為貨幣金額形式(e.g.: (¤1,234.56))
- n:將數字串化為逗號三位分隔(-d,ddd,ddd.ddd…")形式(e.g.: -1,234.56)
[S] Number.parseLocale (value)
從字串表示的本地數字解析成相應的Number類型。使用Sys.CultureInfo.CurrentCulture得到當前的地區屬性。
[S] Number.parseInvariant (value)
從字串表示的本地數字解析成相應的浮點數Number類型。value中可以包含逗號分隔字元(,)或是正負(+-)號。
var a = new Number();
a = Number.parseInvariant("4");
var b = new Number(2);
var c = Number.parseInvariant("1.53") + a + b;
// c = 7.53
Error相關的方法
- [S] Error.argument:根據指定的異常資訊和非法的參數建立一個Sys.ArgumentException類型的異常。
- [S] Error.argumentNull:根據指定的異常資訊和為Null的參數建立一個Sys.ArgumentNullException 類型的異常。
- [S] Error.argumentType:根據指定的異常資訊、期待參數類型和實際參數類型建立一個Sys.ArgumentTypeException 類型的異常。
- [S] Error.argumentUndefined:根據指定的異常資訊和為定義的參數建立一個Sys.ArgumentUndefinedException類型的異常。
- [S] Error.create:根據指定的異常資訊建立一個Error對象。
- [S] Error.invalidOperation:根據指定的異常資訊和引發該異常的參數建立一個Sys.InvalidOperationException 類型的異常。
- [S] Error.notImplemented:根據指定的異常資訊建立一個Sys.NotImplementedException類型的異常。
- [S] Error.argumentOutOfRange:根據指定的異常資訊和引發該異常的參數建立一個Sys.ArgumentOutOfRangeException類型的異常。
- [S] Error.parameterCount:根據指定的異常資訊建立一個Sys.ParameterCountException 類型的異常。
- Error.popstackFrame:將該Error執行個體的fileName和lineNumber欄位更新為該Error被擲出時的位置,而不是該Error被建立時的位置。
// Throw a standard exception type
var err = Error.argumentNull("input", "A parameter was undefined.");
throw err;
// Throw a generic error with a message and associated errorInfo object.
var errorInfoObj = { name: "SomeNamespace.SomeExceptionName",
someErrorID: "436" };
var err = Error.create("A test message", errorInfoObj);
throw err;