diff --git a/spec/suites/core/UtilSpec.js b/spec/suites/core/UtilSpec.js index 3e7d3ec0..d66e6236 100644 --- a/spec/suites/core/UtilSpec.js +++ b/spec/suites/core/UtilSpec.js @@ -49,13 +49,14 @@ describe('Util', function () { var fn = sinon.spy(), foo = {}, a = {}, - b = {}; + b = {}, + c = {}; var fn2 = L.Util.bind(fn, foo, a, b); - fn2(); + fn2(c); - expect(fn.calledWith(a, b)).to.be.ok(); + expect(fn.calledWith(a, b, c)).to.be.ok(); }); }); diff --git a/src/core/Util.js b/src/core/Util.js index b9030989..5f7e5dd6 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -18,10 +18,17 @@ L.Util = { return dest; }, - bind: function (fn, obj) { // (Function, Object) -> Function - var args = arguments.length > 2 ? Array.prototype.slice.call(arguments, 2) : null; + bind: function (fn, obj) { + var slice = Array.prototype.slice; + + if (fn.bind) { + return fn.bind.apply(fn, slice.call(arguments, 1)); + } + + var args = slice.call(arguments, 2); + return function () { - return fn.apply(obj, args || arguments); + return fn.apply(obj, args.length ? args.concat(slice.call(arguments)) : arguments); }; },