Backbone.JS View Extend()

The Backbone.JS View Extend() method extends the backbone’s View class to create a custom view class.

Syntax:

Backbone.View.extend (properties, classProperties)   

Parameters:
properties: This parameter is used to specify the properties for instance for the View class.
classProperties: This parameter is used to specify the class properties for the constructor function of the View.

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.View.extend({
initialize:function(){
document.write('HELLO WORLD!!');
} });
var Y = new X();
</script>HELLO WORLD!!
<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.View.extend({ initialize:function(){ document.write('HELLO WORLD!!'); } }); var Y = new X(); </script>HELLO WORLD!!
  

  
Example  
  
  
  
  
  
HELLO WORLD!!  
  


  

Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
HELLO WORLD!!
HELLO WORLD!!
HELLO WORLD!!

Explanation:
In the above example the Extend() method is used to extend the backbone’s View class.