Home  >  Article  >  Web Front-end  >  Ext's extension of basic types ext, extjs, format_extjs

Ext's extension of basic types ext, extjs, format_extjs

WBOY
WBOYOriginal
2016-05-16 18:13:301248browse
1. Array
indexOf(Object o):Number method
remove(Object o):Array method
2. Date
Javascript for date and time The operation is not very convenient, and Ext basically adds more extensions. The more important ones are:
add(String interval,Number value):Date method
where interval represents the period to be added, and the valid string is
ms-------- represents milliseconds
s----------represents seconds
mi---------represents minutes
h----------represents hours
d---------represents day
mo--------represents month
y---------represents year
This method encapsulates Date Implemented by .setxxx method. In addition, this function does not change the value of the original date, but returns a new date object as the result.
format(String format):String method
Basically, its usage is similar to the date formatting function in .net. For the specific format, please refer to the Ext API. By reading its source code, I found that when this function is called for the first time, it first determines whether the specified format has been called before. If it has not been called, a corresponding formatting function is dynamically generated for the format and cached. Doing this can significantly improve the speed of the second call.
3. Function
createCallback method
Generates a callback method for the function. How does this function work?
Copy code The code is as follows:

function add(x,y){
return x y;
}
var add2 = add.createCallback(10,20);
alert(add2());


createDelegate(scope, args, append) method
The function of this method is basically the same as that of createCallback. The difference is that it can specify the context object for calling the original function, while the createCallback method always uses window as the context for function calling.
createInterceptor(fn,[scope]) method
The function of this method is to create an interceptor for the function. Call fn before calling the original function. If fn returns false, it will not be called. original function. The scope parameter specifies the context in which the fn function is called. If not specified, it is the same as the context of the original function or the window object.
createSequence( Function fn, [Object scope] )
This method combines the original function and fn. The final result is to call the original function first, and then call the fn function with the same parameters. The final return value is the return value of the original function.
defer(Number millis, [Object scope], [Array args], [Boolean/Number appendArgs] )
This method can delay calling the original function.
Copy code The code is as follows:

var clock = function(){
var d = new Date();
alert(d.toLocaleTimeString());
}

clock();
clock.defer(10000);


4. Number
constrain(Number min, Number max)
No explanation, you understand.
5. string
format( String string, String value1, String value2… ): String
Its function is basically the same as the formatting in .net, but it is simpler and not The writing method {0:d} is supported, and only the writing method {0} is supported. After looking at its source code, it's super simple.
Copy code The code is as follows:

format : function(format){
var args = Ext.toArray(arguments, 1);
return format.replace(/{(d )}/g, function(m, i){
return args[i];
});
}


Basically, this is a very useful function that allows us to write less code that spells out strings, which is really hard to read.
trim(): String
It is somewhat useful and does not explain.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn