Thursday, July 10, 2025
HomeLanguagesJavascriptBackbone.js changed Model

Backbone.js changed Model

In this article, we will discuss Backbone.js changed model. The Backbone.js changed model is used to change the attributes that are changed after setting the attributes by using the set() method.

Syntax:

Backbone.Model.changed

Note: It takes no parameters.

Example 1: In this example, we will change the book_name:

HTML




<!DOCTYPE html>
<html>
  
<head>
        type="text/javascript"></script>
    <script src=
        type="text/javascript"></script>
    <script src=
        type="text/javascript"></script>
  
    <script type="text/javascript">
        Books = Backbone.Model.extend({
            defaults: {
                book_name: 'Intro to html',
                author: 'X'
            },
            initialize: function () {
                this.bind("update:book_name", function (model) {
                    var bname = model.get("book_name");
                    var bauthor = model.get("author");
                });
            }
        });
          
        var final = new Books();
        document.write("Actual Value: ",
            final.get("book_name"));
        document.write("<br>");
        final.set({ book_name: 'PHP Introduction' });
        document.write("Changed Value: ",
            final.get("book_name"));  
    </script>
</head>
  
</html>


Output:

Actual Value: Intro to html
Changed Value: PHP Introduction

Example 2: In this example, we will change the author

HTML




<!DOCTYPE html>
<html>
  
<head>
        type="text/javascript"></script>
    <script src=
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
  
    <script type="text/javascript">
        Books = Backbone.Model.extend({
            defaults: {
                book_name: 'Intro to html',
                author: 'X'
            },
            initialize: function () {
                this.bind("update:book_name", function (model) {
                    var bname = model.get("book_name");
                    var bauthor = model.get("author");
                });
            }
        });
        var final = new Books();
        document.write("Actual Value: ",
            final.get("author"));
        document.write("<br>");
        final.set({ author: 'Y' });
        document.write("Changed Value: ",
            final.get("author"));  
    </script>
</head>
  
<body></body>
  
</html>


Output:

Actual Value: X
Changed Value: Y

Reference: https://backbonejs.org/#Model-changed

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
32126 POSTS0 COMMENTS
Milvus
66 POSTS0 COMMENTS
Nango Kala
6510 POSTS0 COMMENTS
Nicole Veronica
11658 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11714 POSTS0 COMMENTS
Shaida Kate Naidoo
6605 POSTS0 COMMENTS
Ted Musemwa
6865 POSTS0 COMMENTS
Thapelo Manthata
6565 POSTS0 COMMENTS
Umr Jansen
6558 POSTS0 COMMENTS