CodesJava

Easy learning with example program codes

Backbone.JS Clone() collection

The Backbone.JS Clone() collection method is used to get the shallow copy of the specified object.

Syntax:

Collection.Clone ( )   

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.Model.extend();   
var Y =new X({  
name: 'Tom Jones'  
});  
var Coll = Backbone.Collection.extend({  
model: X     
});  
var Z = new Coll();    
var value = Z.clone(Y.get('name'));   
value.name="Jerry Jones";  
document.write("New Collection's Instance: ", JSON.stringify(value.name));  
</script>  
</body>  
</html>

Output:

New Collection's Instance: "Jerry Jones"

Explanation:
In the above example, the Clone() method used the Get() method to retrieve the ‘name’ attribute of the model.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status