The Backbone.JS PreviousAttributes() model is used to get the state of all the attributes prior to the last change event.
Syntax:
Model.PreviousAttributes ()
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 = new Backbone.Model({
msg1: "HELLO WORLD.",
msg2: "Welcome."
});
X.set('msg1', 'Hello World.');
document.write("All the previous attributes of the model X before the change are: ");
document.write("<br>");
document.write(JSON.stringify(X.previousAttributes()));
</script>All the previous attributes of the model X before the change are: <br>{"msg1":"HELLO WORLD.","msg2":"Welcome."}
<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 = new Backbone.Model({
msg1: "HELLO WORLD.",
msg2: "Welcome."
});
X.set('msg1', 'Hello World.');
document.write("All the previous attributes of the model X before the change are: ");
document.write("<br>");
document.write(JSON.stringify(X.previousAttributes()));
</script>All the previous attributes of the model X before the change are: <br>{"msg1":"HELLO WORLD.","msg2":"Welcome."}
Example All the previous attributes of the model X before the change are:
{"msg1":"HELLO WORLD.","msg2":"Welcome."}
Output:
All the previous attributes of the model X before the change are:
{"msg1":"HELLO WORLD.","msg2":"Welcome."}
All the previous attributes of the model X before the change are:
{"msg1":"HELLO WORLD.","msg2":"Welcome."}
All the previous attributes of the model X before the change are: {"msg1":"HELLO WORLD.","msg2":"Welcome."}
Explanation:
In the above example, all the previous attributes of the model X before the change are returned as the output.