Dojo learning notes (5. dojo. Lang. array & dojo. Lang. func & dojo. String. Extras

Source: Internet
Author: User
Dojo learning notes (5. dojo. Lang. array & dojo. Lang. func & dojo. String. Extras)

Module: dojo. Lang. Array

Dojo. Lang. Has
Determines whether an object has a specified attribute. But is this method useful? It is better to directly use if (name in OBJ)
Usage example:
Dojo. Lang. Has (Dojo. Lang, "has"); // will return true

Dojo. Lang. isempty
Determines whether the object or array is empty.
Usage example:
Dojo. Lang. isempty ({A: 1}); // will return false
Dojo. Lang. isempty ([]); // will return true

Dojo. Lang. Map
Call a specified method to process a specified array or string
Usage example:
Dojo. Lang. Map ([, 5], function (x) {return x * X;}); // will return [, 25]

Dojo. Lang. foreach
Traverses the specified array or string and calls the specified method for the element.
Usage example:
Dojo. Lang. foreach ("ABC", function (x) {alert (x );});

Dojo. Lang. Every
Check whether all the specified arrays meet the conditions of 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 false is returned.

Dojo. Lang. Some
Check whether the specified array partially meets the conditions of the specified method.
Usage example:
Dojo. Lang. Some ([1,-2, 3], function (x) {return x> 0 ;}); // The specified array has an element greater than 0, so true is returned.

Dojo. Lang. Filter
Filters the specified array based on the specified method.
Usage example:
Dojo. Lang. Filter ([1,-2, 3], function (x) {return x> 0 ;}); // will return [1, 3]

Dojo. Lang. unnest
Converts a specified parameter 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
Attaches the specified method to 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 the method reference of the specified name of the 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? See this article: 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, you can ignore the first N parameters.
Usage example:
Function add (A, B)
{
Return A + B;
}
Dojo. Lang. curryarguments (null, add, [1, 2, 3, 4], 2); // will return 5 (= 2 + 3)

Dojo. Lang. trythese
The test parameter specifies all functions and returns the function value whose first return value is not 0.
From seno:
The methods of dojo. Lang. trythese are the same as those of try. These () in prototype,
Xmlnode. Text is useful in Some browsers, but xmlnode. textcontent works normally in other browsers. Using the try. These () method, we can get the return value of the method that works normally.
<SCRIPT>
Function getxmlnodevalue (xmlnode ){
Return try. These (
Function () {return xmlnode. Text ;},
Function () {return xmlnode. textcontent ;)
);
}

Dojo. Lang. delaythese
I don't understand how to use this function.

Module: dojo. String. Extras

Dojo. String. substituteparams
Similar to the string. Format function in C #
% {Name} must be consistent with the input Object Name in case. Otherwise, an exception occurs.
Usage example:
Dojo. string. substituteparams ("% {0}-% {1}-% {2}", "A", "B", "C "); // will return "a-B-c"
Dojo. string. substituteparams ("% {name }:% {value}", {name: "name", value: "value"}); // will return "Name: Value"

Dojo. String. capitalize
Uppercase letters of each word
Usage example:
Dojo. String. capitalize ("Show me love"); // will return "Show me love"

Dojo. String. isblank
Checks whether the input string is null or is completely blank. If the input object is not a string, true is returned.
Usage example:
Dojo. String. isblank ("1"); // will return false

Dojo. String. Escape
Parameter 1 is type and can be passed in XML/html/XHTML, SQL, Regexp/RegEx, JavaScript/JScript/JS, and ASCII
The string will be encoded according to the passed type
Usage example:
Dojo. String. Escape ("html", "<input type = 'text' value =''/> "); // will return" & lt; Input
Type = 'text' value = ''/& gt ;"

Dojo. String. encodeascii
Dojo. String. escapexml
Dojo. String. escapesql
Dojo. String. escaperegexp
Dojo. String. escapejavascript
Dojo. String. escapestring
These functions are called by dojo. String. Escape.

Dojo. String. Summary
Get the thumbnail version of the input string
Usage example:
Dojo. String. Summary ("1234567890", 5); // will return "12345 ..."

Dojo. String. endswith
Determines whether the input string ends with the specified string.
Usage example:
Dojo. String. endswith ("ABCDE", "E"); // will return false
Dojo. String. endswith ("ABCDE", "E", true); // will return true

Dojo. String. endswithany
Determines whether the input string ends with any specified string.
Usage example:
Dojo. String. endswithany ("ABCDE", "E", "E"); // will return true

Dojo. String. startswith
Determines whether the input string starts with the specified string.
Usage example:
Dojo. String. startswith ("ABCDE", "A"); // will return false
Dojo. String. startswith ("ABCDE", "A", true); // will return true

Dojo. String. startswithany
Determines whether the input string starts with any specified string.
Usage example:
Dojo. String. startswithany ("ABCDE", "A", "A"); // will return true

Dojo. String. Has
Determines whether the input string contains any specified string
Usage example:
Dojo. String. Has ("ABCDE", "1", "23", "ABC"); // will return true

Dojo. String. normalizenewlines
Convert the format of carriage return to line feed as required
Usage example:
Dojo. String. normalizenewlines ("A/R/Nb/R/N", "/R"); // will return "A/Rb/R"

Dojo. String. splitescaped
Converts a string to an array by separator.
Usage example:
Dojo. String. splitescaped ("A // _ B _c", '_'); // will return ["A // _ B", "C"]

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.