callbacks.fireWith()

Call all callbacks in a list with the given context and arguments.

.callbacks.fireWith(context, args)🡢 Callbacks

context AnythingA reference to the context in which the callbacks in the list should be fired.
args ArrayLikeObjectAn array or array-like object of arguments to pass to the callbacks in the list. If omitted or undefined, no arguments will be passed.

This method returns the Callbacks object onto which it is attached (this).

Use callbacks.fireWith() to fire a list of callbacks with a specific context and an array of arguments:

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

var callbacks = $.Callbacks();

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

// Fire the callbacks on the list using the context "window"
// and an arguments array

callbacks.fireWith(window, ["foo", "bar"]);
// Outputs: "Received: foo, bar"
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 :)