Home  >  jQuery

Example of callbacks.fireWith() in jQuery

March 30, 2013
fireWith() in jQuery executes the callback methods with a context and array of arguments. fireWith() is used as
callbacks.fireWith( context, [array of arguments]);
 
In below example, we have a cal method that takes two numbers to add it. Here as a context we have called window.

<html>
<body>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script>

var cal = function(a,b) {
	console.log(a+b);
};

var callbacks = $.Callbacks();

callbacks.add( cal );

callbacks.fireWith( window, [3,2]);

</script>
</body>
</html>
 
 
In console output will be 5
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us