Dojo API略解续

简介:
dojo.lang.string
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.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)

处理数组相关api

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]
分类:  JAVASCRIPT, Dojo


本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2011/07/26/2117533.html,如需转载请自行联系原作者
目录
相关文章
|
Web App开发 JSON 前端开发
|
3月前
|
缓存 监控 前端开发
顺企网 API 开发实战:搜索 / 详情接口从 0 到 1 落地(附 Elasticsearch 优化 + 错误速查)
企业API开发常陷参数、缓存、错误处理三大坑?本指南拆解顺企网双接口全流程,涵盖搜索优化、签名验证、限流应对,附可复用代码与错误速查表,助你2小时高效搞定开发,提升响应速度与稳定性。
|
5月前
|
JSON API 数据安全/隐私保护
深度分析淘宝卖家订单详情API接口,用json返回数据
淘宝卖家订单详情API(taobao.trade.fullinfo.get)是淘宝开放平台提供的重要接口,用于获取单个订单的完整信息,包括订单状态、买家信息、商品明细、支付与物流信息等,支撑订单管理、ERP对接及售后处理。需通过appkey、appsecret和session认证,并遵守调用频率与数据权限限制。本文详解其使用方法并附Python调用示例。
|
3月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
4月前
|
数据可视化 测试技术 API
从接口性能到稳定性:这些API调试工具,让你的开发过程事半功倍
在软件开发中,接口调试与测试对接口性能、稳定性、准确性及团队协作至关重要。随着开发节奏加快,传统方式已难满足需求,专业API工具成为首选。本文介绍了Apifox、Postman、YApi、SoapUI、JMeter、Swagger等主流工具,对比其功能与适用场景,并推荐Apifox作为集成度高、支持中文、可视化强的一体化解决方案,助力提升API开发与测试效率。
|
3月前
|
JSON API 数据安全/隐私保护
Python采集淘宝拍立淘按图搜索API接口及JSON数据返回全流程指南
通过以上流程,可实现淘宝拍立淘按图搜索的完整调用链路,并获取结构化的JSON商品数据,支撑电商比价、智能推荐等业务场景。
|
4月前
|
JSON 前端开发 API
如何调用体育数据足篮接口API
本文介绍如何调用体育数据API:首先选择可靠服务商并注册获取密钥,接着阅读文档了解基础URL、端点、参数及请求头,然后使用Python等语言发送请求、解析JSON数据,最后将数据应用于Web、App或分析场景,同时注意密钥安全、速率限制与错误处理。
542 152
|
5月前
|
JSON 算法 安全
淘宝商品详情API接口系列,json数据返回
淘宝开放平台提供了多种API接口用于获取商品详情信息,主要通过 淘宝开放平台(Taobao Open Platform, TOP) 的 taobao.tbk.item.info.get(淘宝客商品详情)或 taobao.item.get(标准商品API)等接口实现。以下是关键信息及JSON返回示例:
|
3月前
|
人工智能 自然语言处理 测试技术
Apipost智能搜索:只需用业务语言描述需求,就能精准定位目标接口,API 搜索的下一代形态!
在大型项目中,API 数量庞大、命名不一,导致“找接口”耗时费力。传统工具依赖关键词搜索,难以应对语义模糊或命名不规范的场景。Apipost AI 智能搜索功能,支持自然语言查询,如“和用户登录有关的接口”,系统可理解语义并精准匹配目标接口。无论是新人上手、模糊查找还是批量定位,都能大幅提升检索效率,降低协作成本。从关键词到语义理解,智能搜索让开发者少花时间找接口,多专注核心开发,真正实现高效协作。
|
4月前
|
JSON API 数据安全/隐私保护
Python采集淘宝评论API接口及JSON数据返回全流程指南
Python采集淘宝评论API接口及JSON数据返回全流程指南