CodesJava

Easy learning with example program codes

Backbone.JS Initialize()

The Backbone.JS Initialize() model invokes the class’s constructor when model is created.

Syntax:

new Model(attributes, options)   

Parameters:
attributes: This parameter is used to define properties of a model.
options: This parameter is used to specify the options such as id, name etc to be used with attributes.

Example:

<!DOCTYPE html>  
<html>  
<head>  
<title> Model 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">  
X = Backbone.Model.Initialize({  
initialize: function(){  
document.write("Hello World!");  
}  
});  
var Y = new X;  
</script>  
</head>  
</html>

Output:

Hello World!

Explanation:
The Backbone.JS Initialize() model will invoke the class’s constructor when model is created.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status