namespaces - Polymer components don't encapsulate javascript -


i know encapsulation of javascript not part of web component w3c spec but, strategies avoiding global namespace pollution polymer?

for example, if include <script src="./jquery.js"></script> in polymer component $ leaks the host page's window object. problematic me using polymer in chrome extension.

one way might make jquery-api.html this:

<script src="[path.to]jquery.js"></script> <script> (function() {   // make local $   var $ = window.$;   // kill globals   $.noconflict(true);   // make $ available via custom-element registry   polymer({     is: 'jquery-api',     $() {      return $;     }   }); })(); </script> 

then use anywhere need this:

<link rel="import" href="jquery-api.html"> <script> (function() {   var $ = document.createelement('jquery-api').$;   polymer({     is: 'jquery-user'     /* can use $ in here */   }); })(); </script> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -