Decouple the DOM events from expensive functions.
MIT License
Decouple the DOM events from expensive functions.
$ npm install decouple
$ bower install decouple
$ spm install decouple
$ component install pazguille/decouple
function foo(event) {
console.log('foo');
// The function receive the scroll event as parameter.
console.log(event);
// The function context is the given node.
console.log(this.scrollTop);
}
function bar() {
console.log('bar');
}
decouple(document.querySelector('#box'), 'scroll', foo);
Decouple the DOM event
from the listener
on give node
. Returns the listener handler.
node
{HTMLElement} - A given HTMLElement
.event
{String} - A given DOM event
.listener
{Function} - A given listener
to execute when the given event
is fired.decouple(window, 'scroll', fn);
MIT license. Copyright © 2016.