Sunday, February 1, 2026
HomeLanguagesJavascriptBackbone.js previous Model

Backbone.js previous Model

The Backbone.js previous model is used to get the previous value of the changed attributes, while the change event occurs in a given model. It will return the actual attribute of the model.

Syntax:

Backbone.Model.previous(attribute);

Parameter Value: It accepts one parameter, which is described below:

  • attribute: This parameter specifies the model’s property.

Example 1: In this example, we are creating a model named orders and changing orderid. After that, we are applying the previous model to return the previous value.

HTML




<!DOCTYPE html>
<html>
<head>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
</head>
  
<body>
    <script type="text/javascript">
    var orders = new Backbone.Model({
        orderid: 180,
        ordername: 'clothes',
        address: 'guntur'
    });
    orders.set('orderid', 21);
    document.write(JSON.stringify(orders.previous('orderid')));
    </script>
</body>
</html>


Output:

180

Example 2: In this example, the item value is changed & accordingly displays both the values i.e. the last value & the changed value.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
    <script src=
            type="text/javascript">
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var Fruit = new Backbone.Model({
            item: "Grape",
            taste: "sweet."
        });
        Fruit.set('item', 'GRAPES');
        document.write("Item's value after set: ", 
            JSON.stringify(Fruit.changedAttributes()));
        document.write("<br>");
        document.write("Item's Last value: ",
            Fruit.previous('item'));
    </script>
</body>
</html>


Output:

Item's value after set: {"item":"GRAPES"}
Item's Last value: Grape

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

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
32478 POSTS0 COMMENTS
Milvus
124 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6918 POSTS0 COMMENTS