The ECMAScript 4 proposal stated that this feature would be added to the ES4 specification, but later in the ES4-discuss mailing list discussion, this proposal may be abandoned.
However, you can implement these methods similarly by adding call and apply methods to RegExp.prototype. It not only helps in functional design, but also enables the implementation of duck-typed code that is valid for both functions and regular expressions. So let's add these methods.
RegExp.prototype.call = function (context, str) {
return this.exec(str);
};
RegExp.prototype.apply = function (context, args) {
return this.exec(args[0] );
}; Note that the above two methods completely ignore the context parameter. You can submit null or any other object as context, and you will get the return value of the regular exec method similarly. Using the above method, it becomes much easier to use regular expressions and functions normally no matter what the situation. Some obvious examples, such as these are useful in array iteration in JavaScript 1.6. The following filter, every, some, and map methods can be executed across browsers.
if (!Array.prototype.filter) {
// Returns an array. If the provided filter function returns true, then returns the elements in the existing array.
Array.prototype.filter = function (func, context) {
var results = [];
for (var i = 0; i < this.length; i++) {
if (i in this && func.call( context, this[i], i, this))
results.push(this[i]);
results.push(this[i]); return results;
if };
if (!Array.prototype.every) {
// Return true , if each element in the array satisfies the provided test function.
Array.prototype.every = function (func, context) {
for (var i = 0; i < this.length; i++) {
if (i in this && !func.call(context, this[i] , i, this))
An element satisfies the provided test function .
Array.prototype.some = function (func, context) {
for (var i = 0; i < this.length; i++) {
if (i in this && func.call(context, this[i], i, this) re Retarn True;
}
Return false;
};
}
IF (! Array.prototype.map) {
// Return a array, the function provided by each element call in the existing array The return value.
Array.prototype.map = function (func, context) {
var results = [];
for (var i = 0; i < this.length; i++) {
if (i in this)
results[i ] = Func.Call (Context, this [i], i, this);
}
Return Results;
};
} Because the EXEC method returns the array or NULL value, it will be properly converted into True and False, above The code allows us to use it like this: ["a","b","ab","ba"].filter(/^a/), which returns all values starting with "a": ["a"," ab"].
Indeed, Array.prototype.filter has been implemented in Firefox, because the indirect call of exec already works in this browser. However, if the filter does not add the RegExp.prototype.call method, it cannot be executed across browsers.
The above introduces the solution to the problem that cf cannot full screen win7. The method of calling regular function under js is attached with the code, including the solution to the problem that cf cannot full screen win7. I hope it will be helpful to friends who are interested in PHP tutorials.