Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to use Module Pattern instead for Backbone's View loader #517

Closed
rkulla opened this issue Apr 4, 2013 · 2 comments
Closed

Suggestion to use Module Pattern instead for Backbone's View loader #517

rkulla opened this issue Apr 4, 2013 · 2 comments

Comments

@rkulla
Copy link
Contributor

rkulla commented Apr 4, 2013

The appView code in architecture-examples/backbone/js/views/app.js is wrapped in an unnecessary jQuery DOMReady check. While this is a good idea for the main App initialization (the top-level app.js), it can slow the app from rendering (slight as it is) because it waits for the DOM to be ready before doing anything.

It also shows $ as a parameter but doesn't pass anything explicitly. This could lead to a conflict if other code did something to $. It would be more explicit that we're using jQuery if we passed it to the immediately invoked function expression.

Both of the above things can be accomplished by simply changing:

$(function ($) {
    use 'strict';
    app.AppView = Backbone.View.extend({
    ...
 });

To:

(function ($) {
    use 'strict';
    app.AppView = Backbone.View.extend({
    ....
}){jQuery);

Well, technically it's not a module pattern since we're not returning anything.

This same technique would also go for any of the Backbone Views, such as views/todos.js -- which accesses jQuery via an "implied global" called $.

If this sounds reasonable, I can submit a patch. Thanks.

@sindresorhus
Copy link
Member

Makes sense to me. @addyosmani @passy ?

@passy
Copy link
Member

passy commented Apr 5, 2013

Yes, if we don't need to wait for domready let's get rid of it by all means.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants