Several methods of fix-ie5.js extension not available in ie5

Source: Internet
Author: User
Tags stringreplace

Javascript in ie5:
Array does not support push (), pop (); function does not support apply (); The String object's replace method does not support replacement into a processing function.
Use the following Code The above method is invalid in ie5.
/*
Fix-ie5.js, version 1.0 (pre-release) () X3
Copyright 2005, Dean Edwards
Web: http://dean.edwards.name/

This software is licensed under the CC-GNU lgpl
Web: http://creativecommons.org/licenses/LGPL/2.1/
*/

If (/MSIE 5.0/. Test (navigator. useragent) New Function (){

VaR $ apply = function ($ function, $ object, $ arguments ){
$ Function. Apply ($ object, $ arguments );
};

// fix string. replace
If (''. replace (/^/, string) {
// preserve string. replace
VaR _ stringreplace = string. prototype. replace;
// create string. replace for handling functions
VaR _ functionreplace = function ($ expression, $ replacement) {
var $ match, $ newstring = "", $ string = this;
while ($ string & ($ match = extends expression.exe C ($ string) {
$ newstring + = $ Str Ing. slice (0, $ match. index) + $ apply ($ replacement, this, $ match);
$ string = $ string. slice ($ match. lastindex);
}< br> return $ newstring + $ string;
};
// replace string. replace
string. prototype. replace = function ($ expression, $ replacement) {
This. replace = (typeof $ replacement = "function ")? _ Functionreplace: _ stringreplace;
return this. Replace ($ expression, $ replacement);
};
}

// fix function. Apply
If (! Function. apply) {
var apply = "apply-" + number (new date);
$ $ apply = function (F, O,) {
var R;
O [apply] = f;
switch (. length) {// deconstruct for speed
case 0: r = O [apply] (); break;
case 1: R = O [apply] (a [0]); break;
case 2: r = O [apply] (a [0], a [1]); break;
case 3: r = O [apply] (a [0], a [1], a [2]); break;
case 4: R = O [apply] (a [0], a [1], a [2], a [3]); break;
default:
var AA = [], I =. length-1;
do Aa [I] = "A [" + I + "]"; while (I --);
eval ("r = O [apply] (" + AA + ")");
}< br> Delete o [apply];
return r;
};
// fix icommon
icommon. valueof. prototype. inherit = function () {
return $ apply (arguments. callee. caller. ancestor, this, arguments);
};
}

// array fixes
If (! []. Push) array. prototype. push = function () {
for (VAR I = 0; I This [this. length] = arguments [I];
}< br> return this. length;
};
If (! []. Pop) array. prototype. pop = function () {
var $ item = This [this. length-1];
This. length --;
return $ item;
};

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.