加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dojo学习笔记(二) dojo.lang.array & dojo.lang.func &am

发布时间:2020-12-16 22:06:34 所属栏目:百科 来源:网络整理
导读:模块: dojo.lang.array dojo.lang.has 判断对象是否具有指定属性,不过这个方法有用吗,不如直接使用 if(nameinobj) UsageExample: dojo.lang.has(dojo.lang,"has");//willreturntrue dojo.lang.isEmpty 判断对象或数组是否为空 UsageExample: dojo.lang.is

模块: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.some
检查指定的数组是否部分满足指定方法的条件
UsageExample:
dojo.lang.some([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,sql,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.escapeSql
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"]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读