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.


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


var cal = function(a,b) {

var callbacks = $.Callbacks();

callbacks.add( cal );

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

In console output will be 5

©2022 concretepage.com | Privacy Policy | Contact Us