CodesJava

Easy learning with example program codes

Backbone.JS Clone()


The Backbone.JS Clone() model is used for two main purposes.

  • To create a deep copy of a model.
  • To copy one model object to another object.

Syntax:

Model.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>  
<script type="text/javascript">  
var X  = Backbone.Model.extend();  
var Y=new X({  
msg1: "Hello World.",  
msg2: "Welcome."
});  
var details=Y.clone();   
document.write(JSON.stringify(details));  
</script>  
</head>  
</html>

Output:

{"msg1":"Hello World.","msg2":"Welcome."}

Explanation:
In the above example, the output is a deep clone of the X model.

Please follow and like us:


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