CodesJava

Easy learning with example program codes

Backbone.JS CID()

The Backbone.JS CID() model is used to uniquely identify the model on the client.

Syntax:

Model.CID  

Example:

<!DOCTYPE html> 
<html>   
<head>  
<title> Client id 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();  
document.write("<b> Before setting unique identifier ID: </b>",Y.id); 
document.write("<br>");  
document.write("<b> Before setting unique identifier CID: </b>",Y.cid);  
document.write("<br>");  
var Y = new X({id: 100});  
document.write("<b> After setting unique identifier ID: </b>",Y.id);  
document.write("<br>");  
document.write("<b> After setting unique identifier CID: </b>",Y.cid); 
</script>  
</head>  
</html>

Output:

Before setting unique identifier ID: undefined
Before setting unique identifier CID: c1
After setting unique identifier ID: 1
After setting unique identifier CID: c2

Explanation:
CID is an automatically generated client ID by the Backbone.js, while ID is generated manually.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status