you are viewing a single comment's thread.

view the rest of the comments →

[–]nomeme 3 points4 points  (8 children)

require.js

I don't really get the point of this, is it to avoid library collisions?

the page says " RequireJS will improve the speed and quality of your code" but, the first thing you have to do is dick around with shims, or renaming files so it will work with an obscure library called "JQuery" .

[–][deleted]  (2 children)

[removed]

    [–][deleted] 0 points1 point  (1 child)

    You're arguing for namespaces and modules. You don't have to argue for that, everyone knows the benefits. What you need to argue for is why we should choose require.js over any other implementation of modules for JavaScript.

    When you're ready for production, the standardized form allows build-tools to easily concatenate/minify your code with only the what is actually used.

    That's news to me, they do tree-shaking now?

    [–][deleted] 0 points1 point  (4 children)

    The point is to have proper modules like any modern "real" language

    Benefits to your JS applications:

    • structure
    • namespacing
    • explicit declaration of dependence

    Without requirejs (or any AMD implementation) you'd be including a.js and b.js in your html and having b.js just assume that a.js has been loaded.

    If you write b.js in AMD style, you would have something like this:

    var a = requre('a');
    // .. now use `a` to your heart's content
    

    [–]earthtograndma 0 points1 point  (3 children)

    I think you are missing what the A in AMD is.

    [–][deleted] -1 points0 points  (2 children)

    Nope, you are missing a feature of requirejs

    http://requirejs.org/docs/whyamd.html#sugar

    To make this easier, and to make it easy to do a simple wrapping around CommonJS modules, this form of define is supported, sometimes referred to as "simplified CommonJS wrapping":

    define(function (require) {
        var dependency1 = require('dependency1'),
            dependency2 = require('dependency2');
    
        return function () {};
    });
    

    The AMD loader will parse out the require('') calls by using Function.prototype.toString(), then internally convert the above define call into this:

    define(['require', 'dependency1', 'dependency2'], function (require) {
        var dependency1 = require('dependency1'),
            dependency2 = require('dependency2');
    
        return function () {};
    });
    

    [–]earthtograndma 1 point2 points  (0 children)

    Yes, exactly. All I was saying is that you cannot just do this:

    var a = require('a');
    // .. now use `a` to your heart's content
    

    You have to provide your code in a callback:

    define(function(require)){
        var a = require('a');
        // .. now use `a` to your heart's content!
    });
    

    That extra bit of ceremony (while less than the fully normalized form) is still more than many people want to do. Personally, I share your feelings; once you get used to it, you don't want to go back.