Dojo   发布时间:2022-04-21  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

模块:dojo.lang.array
dojo.lang.has
判断对象是否具有指定属性,不过这个方法有用吗,不如直接使用if(nameinobj)
UsageExample:
dojo.lang.has(dojo.lang,"has");//willreturntrue
dojo.lang.isEmpty
判断对象或数组是否为空
UsageExample:
dojo.lang.isEmpty({a:1});//willreturnfalse
dojo.lang.isEmpty([]);//willreturntrue
dojo.lang.map
调用指定的方法处理指定的数组或字符串
UsageExample:
dojo.lang.map([1,2,3,4,5],function(X){returnx*x;});//willreturn[1,9,16,25]
dojo.lang.forEach
遍历指定的数组或字符串,并对其中的元素调用指定的方法
UsageExample:
dojo.lang.forEach("abc",function(X){alert(X);});
dojo.lang.every
检查指定的数组是否全部满足指定方法的条件
UsageExample:
dojo.lang.every([1,-2,3],function(X){returnx>0;});//
指定的数组不是全大于0的,因此返回false
dojo.lang@L_817_7@me
检查指定的数组是否部分满足指定方法的条件
UsageExample:
dojo.lang@L_817_7@me([1,170); line-height: 165%; font-family: 宋体;">指定的数组有大于
的元素,因此返回true
dojo.lang.filter
根据指定的方法来过滤指定的数组
UsageExample:
dojo.lang.filter([1,function(X){returnx>0;});//willreturn[1,3]
dojo.lang.unnest
把指定的参数或数组转换为一维数组
UsageExample:
dojo.lang.unnest(1,3);//willreturn[1,3]
dojo.lang.unnest(1,[2,[3],[[[4]]]]);//willreturn[1,4]
dojo.lang.toArray
将输入转换为数组
UsageExample:
functiontest()
{
returndojo.lang.toArray(arguments,1);
}
test(1,5);//willreturn[2,5]

dojo.lang.func
dojo.lang.hitch
将指定的方法挂在指定的对象下并返回该方法
UsageExample:
func={test:function(s){alert(s)}};
dojo.lang.mixin(func,{demo:dojo.lang.hitch(func,"test")});
func.demo("demoandtestaresamemethod");
dojo.lang.forWARD
返回自身对象的指定名称方法引用
UsageExample:
func={test:function(s){alert(s)},demo:dojo.lang.forWARD("test")};
func.demo("demoandtestaresamemethod");
dojo.lang.curry
whatiscurry?
请参阅这篇文章http://www.svendtofte.com/code/curried_javas cript/
UsageExample:
functionadd(a,b)
{
returna+b;
}
dojo.lang.curry(null,add,3);//willreturn5
dojo.lang.curry(null,2)(3);//willreturn5

dojo.lang.curry(null,add)(2)(3);//willreturn5
dojo.lang.curry(null,add)()(2)(3);//willreturn5
dojo.lang.curryArguments
dojo.lang.curry 类似,但是可以选择忽略掉前 n 个参数
UsageExample:
functionadd(a,b)
{
returna+b;
}
dojo.lang.curryArguments(null,[1,2);//willreturn 7 (= 3 + 4)
dojo.lang.trythese
测试参数指定所有函数并返回第一个返回值不为 0 函数值,没看懂这个函数哪里用得着
dojo.lang.delaythese
没看懂这个函数怎么用
模块: dojo.String.extras
dojo.String.substituteParams
类似 C# 中的 String.Format 函数
%{name}
要保证与传入的对象的名称大小写一致,否则会出异常
UsageExample:
dojo.String.substituteParams("%{0}-%{1}-%{2}","a","b","c");//willreturn"a-b-c"
dojo.String.substituteParams("%{name}:%{value}",{name:"
名称 ",value:" "});//willreturn" : "
dojo.String.capitalize
把每一个单词的首字母大写
UsageExample:
dojo.String.capitalize("showmelove");//willreturn"ShowMeLove"
dojo.String.isBlank
判断输入字符串是否为空或全是空白字符,如果传入对象为非字符串则也会返回 true
UsageExample:
dojo.String.isBlank("1");//willreturnfalse
dojo.String.escape
参数 1 type ,可传值为 :xml/html/xhtml,@L_675_27@,regEXP/regex,javas cript/js cript/js,ascii
将按照所传 对字符串进行编码
UsageExample:
dojo.String.escape("html","<inputtype='text'value=''/>");//willreturn"<input
type='text'value=''/>"
dojo.String.encodeAscii
dojo.String.escapeXml
dojo.String.escape@L_675_27@
dojo.String.escapeRegExp
dojo.String.escapeJavas cript
dojo.String.escapeString
这些函数也就是 dojo.String.escape 调用的,这里无需多说
dojo.String.sumMary
取得输入字符串的缩略版本
UsageExample:
dojo.String.sumMary("1234567890",5);//willreturn"12345..."
dojo.String.endsWith
判断输入字符串是否以指定的字符串结尾
UsageExample:
dojo.String.endsWith("abcde","E");//willreturnfalse
dojo.String.endsWith("abcde","E",truE);//willreturntrue
dojo.String.endsWithAny
判断输入字符串是否以指定的任意字符串结尾
UsageExample:
dojo.String.endsWithAny("abcde","e");//willreturntrue
dojo.String.startsWith
判断输入字符串是否以指定的字符串开头
UsageExample:
dojo.String.startsWith("abcde","A");//willreturnfalse
dojo.String.startsWith("abcde","A",truE);//willreturntrue
dojo.String.startsWithAny
判断输入字符串是否以指定的任意字符串开头
UsageExample:
dojo.String.startsWithAny("abcde","a");//willreturntrue

dojo.String.has
判断输入字符串是否含有任意指定的字符串
UsageExample:
dojo.String.has("abcde","1","23","abc");//willreturntrue
dojo.String.normalizeNewlines
按要求转换回车换行的格式
UsageExample:
dojo.String.normalizeNewlines("a/r/nb/r/n","/r");//willreturn"a/rb/r"
dojo.String.splitEscaped
将字符串按分隔符转换为数组 UsageExample: dojo.String.splitEscaped("a//_b_c",'_');//willreturn["a//_b","c"]

大佬总结

以上是大佬教程为你收集整理的dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras全部内容,希望文章能够帮你解决dojo学习笔记(二) dojo.lang.array & dojo.lang.func & dojo.string.extras所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。