CodesJava

Easy learning with example program codes

Backbone.JS Unset()


The Backbone.JS Unset() model removes an attribute from a backboneJS model.

Syntax:

Model.Unset(attribute)   

Parameters:
attribute: This parameter is used to define properties of a model.

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();  
Y.set({ MSG: "HELLO WORLD"});  
document.write("<b>Message after SET:</b> ", Y.get('MSG'));  
Y.unset('MSG');  
document.write("<br>");  
document.write("<b> Message after UNSET:</b> ", Y.get('MSG'));  
</script>  
</head>  
</html>

Output:

Message after SET: HELLO WORLD
Message after UNSET: undefined

Explanation:
After UNSET the message is undefined.

Please follow and like us:


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