Q:

Check if a callback list contains a specific callback using jquery

0

Check if a callback list contains a specific callback.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code:

<!DOCTYPE html>
<html>
<head>
<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>
</head>
<body>
</body>
</html>

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 ) );

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now