Search code examples
jqueryember.jsember-cli

Why prefer Ember.$() vs $()


I see that on lot of Ember-cli projects jQuery is called with Ember.$() instead of $().

Is there a specific reason?


Solution

  • Usually Ember has been imported already, and by using Ember.$ you avoid referencing a global dependency. It's not actually that great an idea, and you can actually import jQuery directly.

    // you can name the import `$` is you do desire
    import jQuery from 'jquery';
    
    jQuery()
    

    Do note, there is a difference between Ember.$() and this.$(). The this version within components is the equivalent of jQuery(this.element).