jQuery: Check if a callback list contains a specific callback

jQuery Fundamental - I : Exercise-49

Check if a callback list contains a specific callback.

Sample solution :

HTML Code:

<!DOCTYPE html>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Check if a callback list contains a specific callback.</title>

JavaScript Code:

// A sample function f1 to be added to a callbacks list
var f1 = function( value1, value2 ) {
  console.log( "Received: " + value1 + "," + value2 );
// A second function f2  which will not be added to the list
var f2 = function( value1, value2 ) {
  console.log( "foobar" );
var callbacks = $.Callbacks();
// Add the function f1
callbacks.add( f1 );
//Find the callbacks which are in the list
console.log( callbacks.has( f1 ) );

console.log( callbacks.has( f2 ) );

See the Pen jquery-fundamental-exercise-49 by w3resource (@w3resource) on CodePen.

Contribute your code and comments through Disqus.

Previous: Fire a list of callbacks with a specific context and an array of arguments.
Next: Lock a callback list in its current state.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter