CodesJava

Easy learning with example program codes

Backbone.JS Clear()

The Backbone.JS Clear() model removes all attributes, including the id attribute also.

Syntax:

Model.Clear (options)   

Parameters:
options: This parameter is used to define options like id, name, etc.

Example:

<!DOCTYPE html>  
<html>  
<head>  
<title> Clear 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({student_name:"Tom", student_id:100});  
document.write("<b>Student Name: </b>", Y.get('student_name')); 
document.write("<br>");  
document.write("<b>Student id: </b>", Y.get('student_id'));  
document.write("<br>");  
document.write("<br>");  
Y.clear();  
document.write("<b>Student Name After using clear:</b> ", 
Y.get('student_name'));
document.write("<br>");  
document.write("<b>Student id After using clear:</b> ", 
Y.get('student_id')); 
</script>  
</head>
</html>

Output:

Student Name: Tom
Student id: 100
 
Student Name After using clear: undefined
Student id After using clear: undefined

Explanation:
After Clear all the attributes of a model are undefined.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status