Friday, October 24, 2025
HomeLanguagesJavascriptBackbone.js off Event

Backbone.js off Event

Backbone.js off Event is used to remove the previously bound callback function to an object. It removes all the callbacks if no context is specified. If no callback is specified all the event’s callbacks are removed. If no event is specified all the callbacks for all the events are removed. 

Syntax: 

Object.off ( event, callback, context ) ;

Parameter Values: It accepts the following parameters:

  • event: It is used to bind an object with an event.
  • callback: It is executed when an event is invoked.
  • context: It is an object which is passed to a callback function.

Example 1: In this example, we will describe the Backbone.js off Event. Here we will see how we remove all the callbacks for any particular event.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>BackboneJS Model off</title>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
  
</head>
  
<body>
    <h1 style="color: green;">
        neveropen
    </h1>
  
    <h3>BackboneJS Model off</h3>
  
    <script type="text/javascript">
  
        var myVal = Backbone.Model.extend(
              { name: 'Hello Guys' }, Backbone.Events);
        var myFunc = function () {
            document.write('This is by first callback <br>');
        };
  
        var myFunc1 = function () {
            document.write('This is by second callback <br>');
        };
  
        myVal.on('log', myFunc);
        myVal.on('log', myFunc1);
        document.write("Before Removing all "
            + "callbacks for log events. <br>");
        myVal.trigger('log');
  
        myVal.off('log');
  
        document.write("<br>After Removing all callback"
            + " for log events nothing will print <br>");
        myVal.trigger('log');  
    </script>
</body>
  
</html>


Output:

Backbone.js off Event

Example 2: In this example we will remove specific callback for all the events and Remove all the callback of model with all the events.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>BackboneJS Model off</title>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
  
</head>
  
<body>
    <h1 style="color: green;">
        neveropen
    </h1>
  
    <h3>BackboneJS Model off</h3>
  
    <script type="text/javascript">
  
        var myVal = Backbone.Model.extend(
              { name: 'Hello Guys' }, Backbone.Events);
        var myFunc = function () {
            document.write('This is by first callback <br>');
        };
  
        var myFunc1 = function () {
            document.write('This is by second callback <br>');
        };
  
        var myFunc2 = function () {
            document.write('This is by third callback <br>');
        };
  
  
        myVal.on('log', myFunc);
        myVal.on('log', myFunc1);
        myVal.on('log', myFunc2);
        document.write("Before Removing myFunc callbacks"
            + " for all events. <br>")
        myVal.trigger('log');
  
        myVal.off(null, myFunc);
        document.write("<br>After Removing all callback "
            + "for log events nothing will print <br>")
        myVal.trigger('log');
  
        myVal.off();
        document.write("<br> Remove all the "
            + "callbacks of myval model ");
        myVal.trigger('log');
    </script>
</body>
  
</html>


Output:

Backbone.js off Event

Reference: https://backbonejs.org/#Events-off

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS