Over a million developers have joined DZone.

Implement Function.apply( ) In IE 4 & 5

·
    IE 4 & 5 don't implement Function.apply( ).
   This workaround is based on code by Aaron Boodman.
  Quoted from JavaScript,the Definitive Guide,5th edition
   



    if (!Function.prototype.apply) {
    Function.prototype.apply = function(object, parameters) {
    var f = this; 
    var o = object || window;
    var args = parameters || []; 


    o._$_apply_$_ = f;


    var stringArgs = [];
    for(var i = 0; i < args.length; i++)
    stringArgs[i] = "args[" + i + "]";


    var arglist = stringArgs.join(",");


    var methodcall = "o._$_apply_$_(" + arglist + ");";


    var result = eval(methodcall);


    delete o._$_apply_$_;

    return result;
    };
    }
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}