The Backbone.JS set() model sets the value of an attribute in the model.
Syntax:
Model.set(attribute)
Parameters:
attribute: This parameter is used to define properties of a model.
Example:
<title>Example</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>
<script type="text/javascript">
var X = Backbone.Model.extend();
var Y = new X();
Y.set({ MSG1: "HELLO", MSG2:"WORLD"});
document.write("The FIRST Message: ", Y.get('MSG1'));
</script>The FIRST Message: HELLO
<!-- Mirrored from www.w3schools.blog/backbonejs-set by HTTrack Website Copier/3.x [XR/YP'2000] -->
<title>Example</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>
<script type="text/javascript">
var X = Backbone.Model.extend();
var Y = new X();
Y.set({ MSG1: "HELLO", MSG2:"WORLD"});
document.write("The FIRST Message: ", Y.get('MSG1'));
</script>The FIRST Message: HELLO
<!-- Mirrored from www.w3schools.blog/backbonejs-set by HTTrack Website Copier/3.x [XR/YP'2000] -->
Example The FIRST Message: HELLO
Output:
The FIRST Message: HELLO
The FIRST Message: HELLO
The FIRST Message: HELLO
Explanation:
The Backbone.JS set() model is setting the value of the attributes in the model.