Module: Dojo.lang.array
Dojo.lang.has
To determine if an object has a specified property, but is this method useful, as a direct use of if (name in obj)
Usage Example:
dojo.lang.has(dojo.lang, "has"); //will return true
dojo.lang.isEmpty
To determine whether an object or array is empty
Usage Example:
dojo.lang.isEmpty({a: 1}); //will return false
dojo.lang.isEmpty([]); //will return true
dojo.lang.map
Invokes the specified method to handle the specified array or string
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
Iterates through the specified array or string and invokes the specified method on the element
Usage Example:
dojo.lang.forEach("abc", function(x) { alert(x); });
dojo.lang.every
Checks whether the specified array satisfies the criteria for the specified method
Usage Example:
Dojo.lang.every ([1,-2,3], function (x) {return x > 0;}); The specified array is not all greater than 0, so returns false
Dojo.lang.some
Checks whether the specified array partially meets the criteria for the specified method
Usage Example:
dojo.lang.some([1,-2,3], function(x) { return x > 0; }); //指定的数组有大于0的元素,因此返回true
dojo.lang.filter
Filters the specified array according to the specified method
Usage Example:
dojo.lang.filter([1,-2,3], function(x) { return x > 0; }); //will return [1, 3]
dojo.lang.unnest
Converts the specified argument or array to a one-dimensional array
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
Convert input to an array
Usage Example:
function test()
{
return dojo.lang.toArray(arguments, 1);
}
test(1,2,3,4,5); //will return [2,3,4,5]
Module: Dojo.lang.func
Dojo.lang.hitch
Hangs the specified method under the specified object and returns the method
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
Returns a method reference for the specified name of its own object
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
Similar to Dojo.lang.curry, but you can choose to ignore the first n parameters
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