日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dojo API略解续

發(fā)布時(shí)間:2024/9/20 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dojo API略解续 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
dojo.lang.string
dojo.string.substituteParams 類似C#中的String.Format函數(shù)
%{name}要保證與傳入的對象的名稱大小寫一致,否則會出異常
Usage Example:
dojo.string.substituteParams("%{0} - %{1} - %{2}", "a", "b", "c"); //will return "a - b - c"
dojo.string.substituteParams("%{name}: %{value}", {name:"名稱",value:"值"}); //will return "名稱: 值"
dojo.string.capitalize 把每一個(gè)單詞的首字母大寫
Usage Example:
dojo.string.capitalize("show me love"); //will return "Show Me Love"
dojo.string.isBlank 判斷輸入字符串是否為空或全是空白字符,如果傳入對象為非字符串則也會返回true
Usage Example:
dojo.string.isBlank(" 1 "); //will return false
dojo.string.escape 參數(shù)1為type,可傳值為: xml/html/xhtml, sql, regexp/regex, javas cript/js cript/js, ascii
將按照所傳type對字符串進(jìn)行編碼
Usage Example:
dojo.string.escape("html", "<input type='text' value='' />"); //will return "<input
type='text' value='' />"
dojo.string.encodeAscii
dojo.string.escapeXml
dojo.string.escapeSql
dojo.string.escapeRegExp
dojo.string.escapeJavas cript
dojo.string.escapeString
這些函數(shù)也就是 dojo.string.escape 所調(diào)用的,這里無需多說
dojo.string.summary取得輸入字符串的縮略版本
Usage Example:
dojo.string.summary("1234567890", 5); //will return "12345..."
dojo.string.endsWith 判斷輸入字符串是否以指定的字符串結(jié)尾
Usage Example:
dojo.string.endsWith("abcde", "E"); //will return false
dojo.string.endsWith("abcde", "E", true); //will return true
dojo.string.endsWithAny 判斷輸入字符串是否以指定的任意字符串結(jié)尾
Usage Example:
dojo.string.endsWithAny("abcde", "E", "e"); //will return true
dojo.string.startsWith 判斷輸入字符串是否以指定的字符串開頭
Usage Example:
dojo.string.startsWith("abcde", "A"); //will return false
dojo.string.startsWith("abcde", "A", true); //will return true
dojo.string.startsWithAny 判斷輸入字符串是否以指定的任意字符串開頭
Usage Example:
dojo.string.startsWithAny("abcde", "A", "a"); //will return true
dojo.string.has 判斷輸入字符串是否含有任意指定的字符串
Usage Example:
dojo.string.has("abcde", "1", "23", "abc"); //will return true
dojo.string.normalizeNewlines 按要求轉(zhuǎn)換回車換行的格式
Usage Example:
dojo.string.normalizeNewlines("a\r\nb\r\n", "\r"); //will return "a\rb\r"
dojo.string.splitEscaped 將字符串按分隔符轉(zhuǎn)換為數(shù)組
Usage Example:
dojo.string.splitEscaped("a\\_b_c", '_'); //will return ["a\\_b", "c"]

模塊:dojo.lang.func
dojo.lang.hitch將指定的方法掛在指定的對象下并返回該方法
Usage Example:
func = {test: function(s) {alert(s)}};
dojo.lang.mixin(func, {demo: dojo.lang.hitch(func, "test")});
func.demo("demo and test are same method");
dojo.lang.forward返回自身對象的指定名稱的方法引用
Usage Example:
func = {test: function(s) {alert(s)}, demo: dojo.lang.forward("test")};
func.demo("demo and test are same method");
dojo.lang.curryWhat is curry? 請參閱這篇文章:http://www.svendtofte.com/code/curried_javas cript/
Usage Example:
function add(a, b)
{
return a + b;
}
dojo.lang.curry(null, add, 2, 3); //will return 5
dojo.lang.curry(null, add, 2)(3); //will return 5
dojo.lang.curry(null, add)(2)(3); //will return 5
dojo.lang.curry(null, add)()(2)(3); //will return 5
dojo.lang.curryArguments與dojo.lang.curry類似,但是可以選擇忽略掉前n個(gè)參數(shù)
Usage Example:
function add(a, b)
{
return a + b;
}
dojo.lang.curryArguments(null, add, [1,2,3,4,5], 2); //will return 7 (= 3 + 4)

處理數(shù)組相關(guān)api

dojo.lang.has判斷對象是否具有指定屬性,不過這個(gè)方法有用嗎,不如直接使用 if(name in obj)
Usage Example:
dojo.lang.has(dojo.lang, "has"); //will return true
dojo.lang.isEmpty判斷對象或數(shù)組是否為空
Usage Example:
dojo.lang.isEmpty({a: 1}); //will return false
dojo.lang.isEmpty([]); //will return true
dojo.lang.map調(diào)用指定的方法處理指定的數(shù)組或字符串
Usage Example:
dojo.lang.map([1,2,3,4,5], function(x) { return x * x;}); //will return [1,4,9,16,25]
dojo.lang.forEach遍歷指定的數(shù)組或字符串,并對其中的元素調(diào)用指定的方法
Usage Example:
dojo.lang.forEach("abc", function(x) { alert(x); });
dojo.lang.every檢查指定的數(shù)組是否全部滿足指定方法的條件
Usage Example:
dojo.lang.every([1,-2,3], function(x) { return x > 0; }); //指定的數(shù)組不是全大于0的,因此返回false
dojo.lang.some檢查指定的數(shù)組是否部分滿足指定方法的條件
Usage Example:
dojo.lang.some([1,-2,3], function(x) { return x > 0; }); //指定的數(shù)組有大于0的元素,因此返回true
dojo.lang.filter根據(jù)指定的方法來過濾指定的數(shù)組
Usage Example:
dojo.lang.filter([1,-2,3], function(x) { return x > 0; }); //will return [1, 3]
dojo.lang.unnest把指定的參數(shù)或數(shù)組轉(zhuǎn)換為一維數(shù)組
Usage Example:
dojo.lang.unnest(1, 2, 3); //will return [1, 2, 3]
dojo.lang.unnest(1, [2, [3], [[[4]]]]); //will return [1, 2, 3, 4]
dojo.lang.toArray將輸入轉(zhuǎn)換為數(shù)組
Usage Example:
function test()
{
return dojo.lang.toArray(arguments, 1);
}
test(1,2,3,4,5); //will return [2,3,4,5]

總結(jié)

以上是生活随笔為你收集整理的Dojo API略解续的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。