BackboneJS-Utility Backbone.noConflict

Descripción

Muestra el valor original del objeto Backbone y permite almacenar referencias a un backbone.

Sintaxis

var backbone = Backbone.noConflict();

Ejemplo

<!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>

Salida

Llevemos a cabo los siguientes pasos para ver cómo funciona el código anterior:

  • Guardar el código anterior en backbone-noConflict.htm archivo

  • Abra este archivo HTML en un navegador.