CodesJava

Easy learning with example program codes

Backbone.JS Router Initialize()


The Backbone.JS Router Initialize() method creates a new constructor. This purpose is served for the router installation.

Syntax:

new Router (options)   

Parameters:
options: This parameter is used to specify the values to be passed to the function.

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>  
</head>  
<body>  
<script type="text/javascript">  
var X = Backbone.Router.extend({  
routes: {  
'': 'route_1',  
'R2': 'route_2'  
},  
route_1: function(){  
document.write("Called Route 1.");  
},  
route_2: function(){  
document.write("Called Route 2.");  
},  });  
var Y = new X;     
Backbone.history.start();  
</script>  
</body>  
</html>

Output:

Called Route 1.

Explanation:
In the above example, the new keyword is the instantiation of the router.

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki