Member-only story

jQuery — Callbacks and Checkboxes

John Au-Yeung
3 min readDec 30, 2020

--

Photo by Glenn Carstens-Peters on Unsplash

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.locked()

We can use the callbacks.locked() method to check if the callbacks list has been locked.

For example, if we write:

const foo = function(value) {
console.log(`foo: ${value}`);
};
const callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.fire("hello");
callbacks.lock();
console.log(callbacks.locked());

Then the last console log should be true since we called lock to lock the callbacks list.

callbacks.remove()

We can remove a callback with the callback.remove method.

For example, we can write:

const foo = function(value) {
console.log(`foo: ${value}`);
};
const callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.fire("hello");
callbacks.remove(foo);
callbacks.fire("world");

We called remove on foo to remove foo from the callbacks list.

Therefore, then 2nd fire callback won’t call foo .

.change()

--

--

No responses yet