Thursday, September 4, 2025
HomeLanguagesJavascriptBackbone.js attributes Model

Backbone.js attributes Model

The Backbone.js attributes model is used to define the property of the given model and uses the update/change the attributes using set() method.

Syntax:

Backbone.Model.attributes

Parameters: It does not accept any parameter.

Example 1: In this example, we will set the book with 1 attribute using the set() method and return 1 attribute using the get() method. The set() method performs a smart update of the collection with a set of items in the model while get() method is used to retrieve a model from a collection.

HTML




<!DOCTYPE html>
<html>
  
<head>
  
    <script src="https://code.jquery.com/jquery-2.1.3.min.js" 
        type="text/javascript"></script>
    <script src=
        type="text/javascript"></script>
    <script src=
        type="text/javascript"></script>
</head>
  
<body>
    <script type="text/javascript">
        var Books = Backbone.Model.extend();
        var book = new Books();
        book.set({ bookid: 23 });
        document.write('bookid: ', book.get('bookid'));
    </script>
</body>
  
</html>


Output:

bookid: 23

Example 2: In this example, we will set the book with 3 attributes using the set() method and return 3 attributes one by one using the get() method.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"
        type="text/javascript"></script>
    <script src=
        type="text/javascript"></script>
    <script src=
        type="text/javascript"></script>
</head>
  
<body>
    <script type="text/javascript">
        var Books = Backbone.Model.extend();
        var book = new Books();
        book.set({ bookid: 23, price: 678, book_name: "css" });
        document.write('bookid: ', book.get('bookid'));
        document.write("<br>");
        document.write('price: ', book.get('price'));
        document.write("<br>");
        document.write('book_name: ', book.get('book_name'));  
    </script>
</body>
  
</html>


Output:

bookid: 23
price: 678
book_name: css

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

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
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS