// IE 4 & IE 5 不包含 Function.apply()
// IE 4 & IE 5 don't implement Function.apply();
if (!Function.prototype.apply)
{
// Invoke this function as a method of the specified object,
// passing the specified parameters. we have to use eval() to do this
// 为指定的对象调用这个方法,需要三个参数。我们实现这个方法要使用eval()
Function.prototype.apply = function (object, parameters)
{
var f = this; // The function to invoke
var o = object || window; // The function to invoke it on
var args = parameters || []; // The arguments to pass
// Temporarily make the function into a method of o
// To do this we use a property name that is unlikely to exist
// 我们用 o 对象的一个临时属性创建 o 对象的一个临时方法
o._$_apply_$_ = f;
// We will use eval() to invoke the method. To do this we've got
// to write the invocation as a string. First build the argument list.
// 我们必须写一个字符串用eval()方法运行.首先创建参数列表
var stringArgs = [];
for (var i=0; i<args.length; i++)
stringArgs[i] = "args[" + i + "]";
// Concatenate the argument strings into a comma-separated list.
// 把参数连接成逗号隔开的字符串
var arglist = stringArgs.join(",");
// Now build the entire method call string
// 现在创建完整的调用方法的字符串
var methodcall = "o._$_apply_$_(" + arglist + ");";
// Use the eval() function to make the methodcall
// 用eval()运行该方法
var result = eval(methodcall);
// Unbind the function from the object
// 从对象中释放该方法
delete o._$_apply_$_;
// And return the result
// 返回结果
return result;
};
}