BackboneJS-Utility Backbone.noConflict

Descrição

Mostra o valor original do objeto Backbone e permite armazenar a referência a um backbone.

Sintaxe

var backbone = Backbone.noConflict();

Exemplo

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

Resultado

Vamos realizar as seguintes etapas para ver como o código acima funciona -

  • Salvar o código acima em backbone-noConflict.htm Arquivo

  • Abra este arquivo HTML em um navegador.