diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 120b7c03d4..72e5748c5d 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -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); }; }; diff --git a/tests/test_BaseTypes.html b/tests/test_BaseTypes.html index 7bc7ee79c8..bfc7971dd7 100644 --- a/tests/test_BaseTypes.html +++ b/tests/test_BaseTypes.html @@ -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) {