CodesJava

Easy learning with example program codes

Backbone.JS Has()


The Backbone.JS Has() model is used to get a true value, if the attribute value is defined with a non-null value or non-undefined value.

Syntax:

Model.has(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({MSG1: "HELLO", MSG2: "WORLD"});  
if(Y.has('MSG2'))  
{  
document.write("We have one more message: True");  
}  
else  
{  
document.write("We have one more message: False");  
}  
</script>  
</head>  
</html>

Output:

We have one more message: True

Explanation:
In this example the Backbone.JS has() model is giving a true value if MSG2 is present in Y.

Please follow and like us:


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