Start extjs Journey: 5. extjs extension of original JavaScript objects

Source: Internet
Author: User
Tags month name
5 extjs extension to the original JavaScript Object

To achieve more powerful functions and better work with the entire extjs framework, extjs extends the array, date, function, number, and string classes in JavaScript, it can be understood as the packaging class in Java, which is the packaging of JavaScript native objects.
1. Array
In addition to the native array object method, the array object extended by extjs also adds the method shown in Table 2-1.

Table 2-1 List of array-type extension methods

Method Name Description
Indexof (obje
Ct o): Number
Checks whether the specified object exists in the array. If yes, returns the corresponding index. If no, returns-1.
Parameter description: O
If not,-1 is returned.
Remove (objec
T o): Array
Deletes a specified object from an array.
Parameter description: O, the object to be deleted.

2. Date
In addition to the methods related to the native date object, the extended date object also adds the method shown in Table 2-2.

Table 2-2 List of date type extension methods

Method Name Description
Date. getmonthnumber (string
Name): Number
The static method returns the value of the month starting from 0 based on the month name.
Parameter description: name, month name.
Date. get1_dayname (Num
Ber day): String
The static method returns the week name based on the number of weeks. 0 corresponds to Sunday.
Parameter description: Day, number of weeks.
Date. getaskmonthname (n
Umber month): String
The static method returns the name of the corresponding month based on the number of months.
Parameter description: month, the number of months.
Date. parsedate (string input,
String format): Date
The static method parses the date String Based on the specified date format and returns the corresponding date.
Object. Note that the method has been parsed in the standard calendar format, that is, January
Corresponding to number 1 rather than number 0.
Parameter description: input, the string to be parsed. Format: String date format.
Add (string interval, number
Value): Date
A convenient method for date calculation, which does not modify the current date object
Is a new date object that contains the calculation result.
Parameter description: interval, which is a valid date interval enumeration value. Value to the current date
The total number.
Between (date start, date
End): Boolean
Check whether the time indicated by the current date is within the specified start date and end date.
Parameter description: START, the start date. End: end date.
Cleartime (Boolean clone ):
Date
Clears the time information of the current date object.
Parameter description: clone. If it is true, a clone of the date object will be created, and then clear
Except the time information of the cloned object and the cloned object is returned, the current date object is not affected,
The default value is false.
Clone (): Date Create and return the clone of an object of the current date.
Format (string format): String Format the current date according to the specified formatted string, and return the date character in the specified format
String.
Parameter description: format, Date Format String.
Getdayofyear (): Number Obtains the number of days in the year of the current date, ranging from 0 to 364 (the leap year is 365 ). Example
For example, if the return value of January 1 is 0, the return value of December 31 in a leap year is 365.
Getdaysinmonth (): Number Obtains the total number of days of the month of the current date object.
Getelapsed ([date]):
Number
The time (in milliseconds) between the current date and the specified date ).
Getfirstdateofmonth (): Date Obtains the date object of the first day of the month of the current date.
Getfirstdayofmonth ():
Number
Obtain the number of weeks on the first day of the month of the current date. 0 indicates Sunday.
Getgmtoffset (Boolean
Colon): String
Returns the time difference between the current date and GMT Standard Time.
Parameter description: Colon. True indicates that a colon is added between the time and minute. The default value is false.
Getlastdateofmonth (): Date Obtains the date object of the last day of the month of the current date.
Getlastdayofmonth ():
Number
Obtain the number of weeks in the last day of the month of the current date. 0 indicates Sunday.
Getsuffix (): String Obtain the English Suffix of the current date.
Gettimezone (): String Obtain the time zone.
Getweekofyear (): Number The week of the year in which the current date is obtained, ranging from 1 to 53.
Isleapyear (): Boolean Determines whether the year of the current date is a leap year.

 

3. Function
In addition to the native function object method, the extended function object also adds the method shown in Table 2-3.

Table 2-3 List of Function Type Extension methods

Method Name Description
Createcallback (): Function Creates a callback function for the current function. Multiple parameters can be bound to one function.
Example:
Function func1 (name ){
Alert (name );
}
// Bind the changed 'Tom 'to the func1 Function
VaR func2 = func1.createcallback ('Tom ');
Func2 ();
Createdelegate ([object OBJ],
[Array ARGs], [Boolean/Number
Appendargs]): Function
Create the proxy function of the current function.
Description of parameters: obj. (optional) This object is used as the scope of the proxy function. ARGs, (optional
(Optional) parameter array. Appendargs. (optional) if it is true, The args is appended to the parameter
After the parameter list, if it is a numeric value, argS is inserted at the appendargs position in the parameter list.
Createinterceptor (Function
FCN, [object scope]): Function
Create an interception function for the current function.
Parameter description: FCN, An Intercept function. This function will be called before the original function is called.
If the return value is false, the original function will not be executed. Scope, (optional) The role of the Interception Function
Field. The default value is the original function scope or window.
Createsequence (function FCN,
[Object Scope]): Function
Create a Composite Function of the current function. After the original function is called, the combined function will continue to be called,
The value is still the return value of the original function.
Parameter description: FCN, a function combination. Scope, (optional) Execution range of combined functions
Defer (number millis, [Object
OBJ], [array ARGs],
[Boolean/Number
Appendargs]): Number
Delayed execution function.
Parameter description: millis, latency (MS ). OBJ, (optional) The scope of the function.
ARGs, (optional) parameter array. Appendargs. (optional) if it is true
After the parameter list is attached, if it is a numerical value, argS is inserted at the appendargs position in the parameter list.

4. Number
In addition to the native number object method, the extended number object method is added as shown in Table 2-4.

Table 2-4 List of number type extension methods

Method Name Description
Constrain (number min, number
Max): Number
Determines whether the current value is within the specified range. If it is within the range
Returns the current value. If the value is smaller than the minimum value, the minimum value is returned. If the value is greater than the minimum value
Then, the maximum value is returned. Note: This method does not modify the current value.
Parameter description: min, minimum value. Max, maximum value.

5. String
In addition to the native String object method, the extended string object also adds the method shown in Table 2-5.

Table 2-5 List of string-type extension methods

Method Name Description
Escape (string): String Static method. replace 'and \ In the string \'\\
Format (string, string value1,
String value2): String
Static method, used to format a string, for example:
String. Format ('{1} {0} {2}', '-', 'Tom ', 'jack ');
Output result: Tom-Jack
Parameter description: string, which must be formatted. Value1, used to replace {0 }. Value2, used to replace {1 }. You can accept any number of parameters.
Leftpad (string, number size,
[String char]): String
Static Method: Fill in the specified character on the left side of the string. This method is very useful for standardized numbers or date formats.
Parameter description: string, the original string. Returns the total length of the string. Char (optional) character used to fill the original string. The default value is "".
Toggle (string value, string other ):
String
A tool for switching between two strings.
The string and value return both other and value. Note that
The method does not modify the original string.
For example, '20180101'. Toggle ('20180101', '0') returns '0'
'20180101'. Toggle ('20180101', '0') returns '20180101'
Parameter description: value, which is the other value compared with the current string. When
Value returned when the original string is equal to the value
Trim (): String Removes spaces at the beginning and end of a string.

 

Related Article

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.