Dojo Learning notes 5. Dojo.lang.array & Dojo.lang.func & Dojo.string.extras

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.