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
Post a Comment