Microsoft AJAX Library Cheat Sheet(5): Number和Error類型的擴充

來源:互聯網
上載者:User

本文為翻譯,英文原版的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格式化數字(地區設定相關)。

 

支援的格式

  1. p:將數字轉為百分比字串(e.g.: -1,234.56 %)
  2. d:將數字裝化為十進位字串,沒有逗號分隔字元(e.g.: -1234.56)
  3. c:將數字轉化為貨幣金額形式(e.g.: (¤1,234.56))
  4. 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相關的方法

  1. [S] Error.argument:根據指定的異常資訊和非法的參數建立一個Sys.ArgumentException類型的異常。
  2. [S] Error.argumentNull:根據指定的異常資訊和為Null的參數建立一個Sys.ArgumentNullException 類型的異常。
  3. [S] Error.argumentType:根據指定的異常資訊、期待參數類型和實際參數類型建立一個Sys.ArgumentTypeException 類型的異常。
  4. [S] Error.argumentUndefined:根據指定的異常資訊和為定義的參數建立一個Sys.ArgumentUndefinedException類型的異常。
  5. [S] Error.create:根據指定的異常資訊建立一個Error對象。
  6. [S] Error.invalidOperation:根據指定的異常資訊和引發該異常的參數建立一個Sys.InvalidOperationException 類型的異常。
  7. [S] Error.notImplemented:根據指定的異常資訊建立一個Sys.NotImplementedException類型的異常。
  8. [S] Error.argumentOutOfRange:根據指定的異常資訊和引發該異常的參數建立一個Sys.ArgumentOutOfRangeException類型的異常。
  9. [S] Error.parameterCount:根據指定的異常資訊建立一個Sys.ParameterCountException 類型的異常。
  10. 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;
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.