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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}