CodesJava

Easy learning with example program codes

Backbone.JS Defaults()

The Backbone.JS Defaults() model is used to set a default value to a model.

Syntax:

Model.Defaults  

Example:

<!DOCTYPE html>  
<html>  
<head>  
<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({  
defaults : {  
"SUBJECT": "Gratitude",  
"MSG": "Thanks for everything."  
}});  
var Y = new X();  
document.write(Y.get('MSG'));  
</script>  
</head>  
</html>

Output:

Thanks for everything.

Explanation:
The Defaults set a default value for the SUBJECT and MSG of the model.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status