BackboneJS - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Backbone.js Utility

Backbone.js Utility

shape Introduction

This chaspter demonstrates about the Backbone.js Utility which defines some set of methods to impliment backbone.utility and following are the concepts covered in this chapter.
  • Backbone.js Utility

Backbone.js Utility

shape Description

Utility class contains set of methods which are used to implement the Backbone utility following are the two methods which are used to manipulate the Backbone.js utility. Backbone.noConflict Which returnback the Backbone objects back to its original state value and provide some facility to store some reference to a Backbone. User can also include backbone third-party websites in which user no need to thrash the existed bone the syntax below demonstrates the Backbone.noConflict () method. [code] var backbone=Backbone.noConflict(); [/code] The code below demonstrates the Backbone.noConflict () method. [html] <!DOCTYPE html> <head> <title>Utility 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> </head> <body> <script> //It is reference to a last parsed verison of Backbone.js this.Backbone = { "Example for Backbone utility": true }; </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script> <script type="text/javascript"> //'Backbone.noConflict()' gives reference to a Backbone before last parsed version of Backbone was loaded var backboneParsed = Backbone.noConflict(); //It looks for the previous version and logs 'true' on the browser document.write(Backbone["Example for Backbone utility"]); //It displays the version of the Backbone.js contained in the new 'backboneParsed' namespace document.write(backboneParsed.VERSION); </script> </body> </html> [/html] Result By running the above code in a preferred browser user can get the following output as shown in below image. Backbone.$ When user have the several copies of jQUery on the page simply user can tell Backbone to use the particular object and its DOM/Ajax library the syntax below demonstrates the Backbone.$ as shown. [code] Backbone.$=$; [/code] The code below demonstrates the Backbone.$ () method. [html] <!DOCTYPE html> <head> <title>Utility 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> </head> <body> <script> //The value specified for the variable '$' in the global scope var $ = {version:'0.1.1',name:'SPLESSONS'}; </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"> //Set the value for the variable after Backbone is loaded Backbone.$ = {version:'1.1.2',name:'SPLESSONS'}; //It displays the defined values in the JSON format document.write("The values after loading Backbone are: ",JSON.stringify(Backbone.$)); </script> </body> </html> [/html] Result By running the above code in a preferred browser user can get the following output as shown in below image.

Summary

shape Key Points

  • Utility consist set of methods to implement Backbone.js Utility.
  • Backbone.$ is used when user have multiple copies of jQuery.