callbacks.has()

Determine whether or not the list has any callbacks attached. If a callback is provided as an argument, determine whether it is in a list.

.callbacks.has(callback)🡢 Boolean

callback FunctionThe callback to search for.

Use callbacks.has() to check if a callback list contains a specific callback:

HTML
// A sample logging function to be added to a callbacks list
var foo = function (value1, value2) {
  console.log("Received: " + value1 + "," + value2);
};

// A second function which will not be added to the list
var bar = function (value1, value2) {
  console.log("foobar");
};

var callbacks = $.Callbacks();

// Add the log method to the callbacks list
callbacks.add(foo);

// Determine which callbacks are in the list
console.log(callbacks.has(foo));
// true
console.log(callbacks.has(bar));
// false
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)