|
Usage Example: function onTime(msg){dojo.debug(msg)}dojo.lang.setTimeout(onTime, 1000, "test"); //1秒后会输出调试信息"test"dojo.lang.setTimeout(dojo, "debug", 1000, "test"); //1秒后会输出调试信息"test" dojo.lang.getNameInObj 获得指定项目在指定对象中的名称 Usage Example: dojo.lang.getNameInObj(dojo, dojo.debug); //will return "debug" dojo.lang.shallowCopy 返回指定对象的浅表复制副本 Usage Example: dojo.lang.shallowCopy({}); //will return a 空对象 dojo.lang.firstValued 返回第一个存在定义的参数 Usage Example: var a;dojo.lang.firstValued(a,2,3); //will return 2 以上全部是自己阅读源代码写的总结,如有错误,还请指明。
//******************************************************************************************************************** Dojo学习笔记(5. dojo.lang.array & dojo.lang.func & dojo.string.extras)
模块: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
| |