From f2ea9b4afa2efbfa61bccbf4f73d8950aac4ec36 Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 28 Aug 2007 18:31:18 +0000 Subject: [PATCH] fix a broken Function.prototype.bind() (Closes #876) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4078 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes.js | 11 ++++++++--- tests/test_BaseTypes.html | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) 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) {