Dojo Learning notes 4. Dojo.string & Dojo.lang

Source: Internet
Author: User
Tags extend require trim

Module: dojo.string.common/dojo.string

Dojo.string.common and dojo.string are the same, as long as one of require can use the following methods

Dojo.string.trim

Remove whitespace from a string

Usage Example:

s = "abc";d Ojo.string.trim (s); would return "ABC" Dojo.string.trim (S, 0); would return "ABC" Dojo.string.trim (S, 1); would return "ABC" Dojo.string.trim (S,-1); would return "ABC"

Dojo.string.trimStart

Remove whitespace from the beginning of a string

Usage Example:
s = " abc ";dojo.string.trimStart(s); //will return "abc "
dojo.string.trimEnd

Remove whitespace from end of string

Usage Example:
s = " abc ";dojo.string.trimEnd(s); //will return " abc"
dojo.string.repeat

Generate a string that is duplicated by the same character (string)

Usage Example:
dojo.string.repeat("a", 4); //will return "aaaa"dojo.string.repeat("1234", 3, "-"); //will return "1234-1234-1234"
dojo.string.pad

Filling strings with characters

Usage Example:
dojo.string.pad("100", 6); //will return "000100"dojo.string.pad("100", 6, "0", 1); //will return "000100"dojo.string.pad("100", 6, "0", -1); //will return "100000"
dojo.string.padLeft

Start with character completion string

Usage Example:
dojo.string.padLeft("100", 6); //will return "000100"
dojo.string.padRight

Use character completion string end

Usage Example:

Dojo.string.padRight ("100", 6); Would return "100000"

Module: Dojo.lang.common/dojo.lang

Dojo.lang.common and Dojo.lang are the same, as long as one of require can use the following methods

Dojo.lang.mixin

Adds an object's methods and properties to another object

Usage Example:

var S1 = {Name: "Testobj", Test1:function () {alert ("This is test1!");} var s2 = {value:1000, test2:function () {alert ("This is test2!");} var d = {};d ojo.lang.mixin (d, S1, S2); After implementation D has all the properties and methods of S1 and S2 d.test1 ();

Dojo.lang.extend

Extends methods and properties for the specified class's prototype

Usage Example:

TestClass = function () {};d Ojo.lang.extend (TestClass, {name: "Demo", Test:function () {alert ("test!");}); var o = new TestClass (); TestClass There was no test method, but extend later there was a test method o.test ();

Dojo.lang.find=dojo.lang.indexof

Finds the position of the specified object in the specified array

Usage Example:
var arr = [1,2,3,3,2,1];dojo.lang.find(arr, 2); //will return 1dojo.lang.find(arr, 2, true); //will return 1dojo.lang.find(arr, "2", true); //will return -1dojo.lang.find(arr, "2", false); //will return 1dojo.lang.find(arr, 2, true, true); //will return 4
dojo.lang.findLast=dojo.lang.lastIndexOf

Finds the position of the specified object in the specified array, looking forward from the back

Usage Example:
var arr = [1,2,3,3,2,1];dojo.lang.findLast(arr, 2); //will return 4dojo.lang.findLast(arr, 2, true); //will return 4dojo.lang.findLast(arr, "2", true); //will return -1dojo.lang.findLast(arr, "2", false); //will return 4
dojo.lang.inArray

Finds whether the specified object is in the specified array

Usage Example:
var arr = [1,2,3];dojo.lang.inArray(arr, 1); //will return truedojo.lang.inArray(arr, 4); //will return false
dojo.lang.isObject

Determines whether the type entered is an object

Usage Example:
dojo.lang.isObject(new String()); //will return truedojo.lang.isObject("123")); //will return false
dojo.lang.isArray

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.