dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras
2008-05-29 14:41
513 查看
模块: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_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个参数
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)
dojo.lang.tryThese
测试参数指定所有函数,并返回第一个返回值不为0的函数值,没看懂这个函数哪里用得着
dojo.lang.delayThese
没看懂这个函数怎么用
模块: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, javas cript/js cript/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.escapeJavas cript
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"]
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_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个参数
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)
dojo.lang.tryThese
测试参数指定所有函数,并返回第一个返回值不为0的函数值,没看懂这个函数哪里用得着
dojo.lang.delayThese
没看懂这个函数怎么用
模块: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, javas cript/js cript/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.escapeJavas cript
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"]
相关文章推荐
- Dojo学习笔记(5. dojo.lang.array & dojo.lang.func & dojo.string.extras)
- dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras
- Dojo学习笔记(5. dojo.lang.array & dojo.lang.func & dojo.string.extras
- Dojo学习笔记(5. dojo.lang.array & dojo.lang.func & dojo.string.extras)
- Dojo学习笔记(4. dojo.string & dojo.lang)
- Dojo学习笔记(4. dojo.string & dojo.lang)
- Dojo学习笔记(4. dojo.string & dojo.lang)
- SplitConcatWithAMP----Array转换为String,"&"连接;String转换为Array,"&"切割
- ognl.OgnlException: target is null for setProperty(null, "y", [Ljava.lang.String;@1d57c7)
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'funcSetId' in 'class java.lang.Integer'
- Dojo学习笔记(6. dojo.io.IO & dojo.io.BrowserIO)
- Mybatis-There is no getter for property named 'tj' in 'class java.lang.String'
- java&nbsp;string.ToCharArray()的…
- java.lang.NumberFormatException: For input string: "0 "
- No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.autoWire.
- Err:The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array
- There is no READABLE property named 'day' in class 'java.lang.String';You have an error in your SQL
- 【转】java.lang.Integer.toHexString(b[n] & 0XFF)中0XFF使用的必要性
- MyBatis There is no getter for property named 'xxx' in 'class java.lang.String'
- Eclipse "Invalid layout of java.lang.String at value"无法运行程序