add Util.invokeEach for hash arguments in event methods
This commit is contained in:
commit
a5e8bc0f49
@ -74,6 +74,33 @@ describe('Util', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#invokeEach', function () {
|
||||
it('calls the given method/context with each key/value and additional arguments', function () {
|
||||
var spy = sinon.spy(),
|
||||
ctx = {};
|
||||
|
||||
var result = L.Util.invokeEach({
|
||||
foo: 'bar',
|
||||
yo: 'hey'
|
||||
}, spy, ctx, 1, 2, 3);
|
||||
|
||||
expect(spy.firstCall.calledWith('foo', 'bar', 1, 2, 3)).to.be.ok();
|
||||
expect(spy.secondCall.calledWith('yo', 'hey', 1, 2, 3)).to.be.ok();
|
||||
|
||||
expect(spy.firstCall.calledOn(ctx)).to.be.ok();
|
||||
expect(spy.secondCall.calledOn(ctx)).to.be.ok();
|
||||
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if the given agument is not object', function () {
|
||||
var spy = sinon.spy();
|
||||
|
||||
expect(L.Util.invokeEach('foo', spy)).to.be(false);
|
||||
expect(spy.called).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#falseFn', function () {
|
||||
it('returns false', function () {
|
||||
expect(L.Util.falseFn()).to.be(false);
|
||||
|
@ -33,6 +33,23 @@ L.Util = {
|
||||
};
|
||||
}()),
|
||||
|
||||
invokeEach: function (obj, method, context) {
|
||||
var i, args;
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
args = Array.prototype.slice.call(arguments, 3);
|
||||
|
||||
for (var i in obj) {
|
||||
if (obj.hasOwnProperty(i)) {
|
||||
method.apply(context, [i, obj[i]].concat(args));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
limitExecByInterval: function (fn, time, context) {
|
||||
var lock, execOnUnlock;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user