模塊:dojo.lang.array
dojo.lang.has
判斷對象是否具有指定屬性,不過這個方法有用嗎,不如直接使用 if(name in obj)
Usage Example:
dojo.lang.has(dojo.lang, "has"); //will return true
dojo.lang.isEmpty
判斷對象或數組是否為空
Usage Example:
dojo.lang.isEmpty({a: 1}); //will return false
dojo.lang.isEmpty([]); //will return true
dojo.lang.map
調用指定的方法處理指定的數組或字符串
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
遍歷指定的數組或字符串,并對其中的元素調用指定的方法
Usage Example:
dojo.lang.forEach("abc", function(x) { alert(x); });
dojo.lang.every
檢查指定的數組是否全部滿足指定方法的條件
Usage Example:
dojo.lang.every([1,-2,3], function(x) { return x > 0; }); //指定的數組不是全大于0的,因此返回false
dojo.lang.some
檢查指定的數組是否部分滿足指定方法的條件
Usage Example:
dojo.lang.some([1,-2,3], function(x) { return x > 0; }); //指定的數組有大于0的元素,因此返回true
dojo.lang.filter
根據指定的方法來過濾指定的數組
Usage Example:
dojo.lang.filter([1,-2,3], function(x) { return x > 0; }); //will return [1, 3]
dojo.lang.unnest
把指定的參數或數組轉換為一維數組
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
將輸入轉換為數組
Usage Example:
function test()
{
return dojo.lang.toArray(arguments, 1);
}
test(1,2,3,4,5); //will return [2,3,4,5]
模塊: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.curry
What is curry? 請參閱這篇文章:
http://www.svendtofte.com/code/curried_javascript/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個參數
Usage Example:
function add(a, b)
{
return a + b;
}
dojo.lang.curryArguments(null, add, [1,2,3,4,5], 2); //will return 5 (= 2 + 3)
dojo.lang.tryThese
測試參數指定所有函數,并返回第一個返回值不為0的函數值
from seno:
dojo.lang.tryThese方法和prototype中的Try.these()方法是一樣的,
xmlNode.text在一些瀏覽器中好用,但是xmlNode.textContent在另一些瀏覽器中正常工作。 使用Try.these()方法我們可以得到正常工作的那個方法的返回值。
<script>
function getXmlNodeValue(xmlNode){
return Try.these(
function() {return xmlNode.text;},
function() {return xmlNode.textContent;)
);
}
dojo.lang.delayThese
dojo.lang.delayThese的用法是:
function(/*Array*/farr, /*Function, optional*/cb, /*Integer*/delay, /*Function, optional*/onend)
根據delay指定的延遲,依次調用farr里面的方法,如果指定了cb,則調用完方法后調用cb。當farr中所有的方法都調用了之后,調用onend。
模塊:dojo.string.extras
dojo.string.substituteParams
類似C#中的String.Format函數
%{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
把每一個單詞的首字母大寫
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
參數1為type,可傳值為: xml/html/xhtml, sql, regexp/regex, javascript/jscript/js, ascii
將按照所傳type對字符串進行編碼
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.escapeJavaScript
dojo.string.escapeString
這些函數也就是 dojo.string.escape 所調用的,這里無需多說
dojo.string.summary
取得輸入字符串的縮略版本
Usage Example:
dojo.string.summary("1234567890", 5); //will return "12345..."
dojo.string.endsWith
判斷輸入字符串是否以指定的字符串結尾
Usage Example:
dojo.string.endsWith("abcde", "E"); //will return false
dojo.string.endsWith("abcde", "E", true); //will return true
dojo.string.endsWithAny
判斷輸入字符串是否以指定的任意字符串結尾
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
按要求轉換回車換行的格式
Usage Example:
dojo.string.normalizeNewlines("a\r\nb\r\n", "\r"); //will return "a\rb\r"
dojo.string.splitEscaped
將字符串按分隔符轉換為數組
Usage Example:
dojo.string.splitEscaped("a\\_b_c", '_'); //will return ["a\\_b", "c"]
posted on 2007-01-17 11:18
周銳 閱讀(311)
評論(0) 編輯 收藏 所屬分類:
Ajax