Member-only story
jQuery — Callbacks
3 min readDec 30, 2020
jQuery is a popular JavaScript for creating dynamic web pages.
In this article, we’ll look at how to using jQuery in our web apps.
callbacks.disable()
We can call callbacks.disable
to disable a callback.
For example, if we have:
const foo = function(value) {
console.log(`foo: ${value}`);
};const callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.fire("hello");
callbacks.disable();
callbacks.fire("world");
Then we call callbacks.disable
to stop the list of callbacks from being called again.
Therefore, we only see:
foo: hello
logged.
callbacks.disabled()
We can use the callbacks.disabled()
method to check if callbacks have been disabled.
For example, we can write:
const foo = function(value) {
console.log(`foo: ${value}`);
};const callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.fire("hello");
callbacks.disable();
console.log(callbacks.disabled());
callbacks.fire("world");
Since we called callbacks.disable
, callbacks.disabled
should log true
.