fix a broken Function.prototype.bind() (Closes #876)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4078 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-08-28 18:31:18 +00:00
parent a84e511c1f
commit f2ea9b4afa
2 changed files with 14 additions and 6 deletions

View File

@@ -167,10 +167,15 @@ Function.prototype.bind = function() {
}
return function(moreargs) {
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
var i;
var newArgs = [];
for (i = 0; i < args.length; i++) {
newArgs.push(args[i]);
}
return __method.apply(object, args);
for (i = 0; i < arguments.length; i++) {
newArgs.push(arguments[i]);
}
return __method.apply(object, newArgs);
};
};

View File

@@ -115,7 +115,7 @@
}
function test_07_Function_bind(t) {
t.plan(5);
t.plan(12);
g_obj = {};
g_Arg1 = {};
@@ -128,12 +128,15 @@
t.ok(y == g_Arg2, "arg2 passed correctly");
t.ok(z == g_Arg3, "arg3 passed correctly");
t.ok(a == g_Arg4, "arg4 passed correctly");
t.eq(arguments.length, 4, "correct number of arguments ((regression test for #876))");
};
var newFoo = foo.bind(g_obj, g_Arg1, g_Arg2);
newFoo(g_Arg3, g_Arg4);
newFoo(g_Arg3, g_Arg4);
//run again to make sure the arguments are handled correctly
newFoo(g_Arg3, g_Arg4);
}
function test_08_Function_bindAsEventListener(t) {