dist/monitor-all.js
function(methodName, method) {
    return function() {

      // Connect the success/error methods for callback style requests.
      // These style callbacks don't need the model or options arguments
      // because they're in the scope of the anonymous callback function.
      var args = _.toArray(arguments), callback = args[args.length - 1];
      if (typeof callback === 'function') {

        // Remove the last element (the callback)
        args.splice(-1, 1);

        // Place options if none were specified.
        if (args.length === 0) {
          args.push({});
        }

        // Place attributes if save and only options were specified
        if (args.length === 1 && methodName === 'save') {
          args.push({});
        }
        var options = args[args.length - 1];

        // Place the success and error methods
        options.success = function(model, response) {
          callback(null, response);
        };
        options.error = function(model, response) {
          // Provide the response as the error.
          callback(response, null);
        };
      }

      // Invoke the original method
      return method.apply(this, args);
    };
  }
function(methodName, method) {
    return function() {

      // Connect the success/error methods for callback style requests.
      // These style callbacks don't need the model or options arguments
      // because they're in the scope of the anonymous callback function.
      var args = _.toArray(arguments), callback = args[args.length - 1];
      if (typeof callback === 'function') {

        // Remove the last element (the callback)
        args.splice(-1, 1);

        // Place options if none were specified.
        if (args.length === 0) {
          args.push({});
        }

        // Place attributes if save and only options were specified
        if (args.length === 1 && methodName === 'save') {
          args.push({});
        }
        var options = args[args.length - 1];

        // Place the success and error methods
        options.success = function(model, response) {
          callback(null, response);
        };
        options.error = function(model, response) {
          // Provide the response as the error.
          callback(response, null);
        };
      }

      // Invoke the original method
      return method.apply(this, args);
    };
  }
function ( methodName , method ) { return function ( ) { // Connect the success/error methods for callback style requests. // These style callbacks don't need the model or options arguments // because they're in the scope of the anonymous callback function. var args = _ . toArray ( arguments ) , callback = args [ args . length - 1 ] ; if ( typeof callback === 'function' ) { // Remove the last element (the callback) args . splice ( - 1 , 1 ) ; // Place options if none were specified. if ( args . length === 0 ) { args . push ( { } ) ; } // Place attributes if save and only options were specified if ( args . length === 1 && methodName === 'save' ) { args . push ( { } ) ; } var options = args [ args . length - 1 ] ; // Place the success and error methods options . success = function ( model , response ) { callback ( null , response ) ; } ; options . error = function ( model , response ) { // Provide the response as the error. callback ( response , null ) ; } ; } // Invoke the original method return method . apply ( this , args ) ; } ; }
Anonymous callback style interface for Backbone.js async methods.

Load this after Backbone.js to add an anonymous function callback style
interface for fetch(), save(), and destroy() in addition to the built-in
success/error style interface.

This adds a shim to the existing interface, allowing either style to be
used.  If a callback function is provided as the last argument, it will
use that callback style.  Otherwise it will use the success/error style.

Example:

customer.save(attrs, options, function(error, response) {
if (error) {
return console.log('Error saving customer', error);
}
console.log('Customer save successful.  Response:', response);
});

The callback gets two arguments - an error object and response object.
One or the other will be set based on an error condition.

The motivation for this callback style is to offer Backbone.js clients a
common coding style for client-side and server-side applications.

@class BackboneCallbacks
Anonymous callback style interface for Backbone . js async methods .