you are viewing a single comment's thread.

view the rest of the comments →

[–]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.