模块: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 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 5 (= 2 + 3)
dojo.lang.tryThese 测试参数指定所有函数,并返回第一个返回值不为0的函数值 from seno: dojo.lang.tryThese方法和prototype中的Try.these()方法是一样的, xmlNode.text在一些浏览器中好用,但是xmlNode.textContent在另一些浏览器中正常工作。 使用Try.these()方法我们可以得到正常工作的那个方法的返回值。 <script> function getXmlNodeValue(xmlNode){ return Try.these( function() {return xmlNode.text;}, function() {return xmlNode.textContent;) ); }