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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>We have one more message: True
<!-- Mirrored from www.w3schools.blog/backbonejs-has by HTTrack Website Copier/3.x [XR/YP'2000] -->
<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>We have one more message: True <!-- Mirrored from www.w3schools.blog/backbonejs-has by HTTrack Website Copier/3.x [XR/YP'2000] -->
 

  
Example  
  
  
  
We have one more message: True  
  


  

Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
We have one more message: True
We have one more message: True
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.