vendredi 22 avril 2016

Prevent Ember.js application from polluting global namespace

I am building an embeddable web application using Ember.js. Application JS will be hosted on my server, but it will be used by some other third-party websites. Basically, this is an embeddable widget, something like Facebook's comments widget.

The problem is that I don't want my JS to pollute third party's global namespace. All I can afford is only ONE global variable defined by me, for example, MyGadget. So I want this variable to be like a namespace for Ember, all its dependencies, and the actual Ember application. Like this:

window.MyGadget.Ember
window.MyGadget.jQuery
window.MyGadget.Pretender
window.MyGadger.App
... and so on

Can this be done in a relatively easy way?




Aucun commentaire:

Enregistrer un commentaire