-
Notifications
You must be signed in to change notification settings - Fork 169
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
define can't be called with only 1 argument #32
Comments
Almond is for built code, where modules are combined together. In that scenario, modules need to be named, which implies at least two arguments. Put another way -- in what way would supporting an anonymous module be useful to do in almond? If it does not have a name, how could another module refer to it? If another module cannot refer to it, then why is it included in a built file? |
es5-shim (https://github.com/kriskowal/es5-shim/) is using that technique because it doesn't provide any new namespace on its own, it only overloads missing standard js api without any dependencies. That's the only case I can think of atm though. In any case, even if it might be abused, being able to have only 1 argument seems to be a mandatory part of the AMD standard. Not supporting it will most certainly cause incompatibilities problems, as already experienced with es5-shim. |
Ah, the expectation when using almond (the second bullet point under Restrictions mentions that it should be used only with named modules. Normally the AMD-aware build tool, like the requirejs optimizer, takes care of that. Modules in source form should not have IDs in them, to allow the most portability, as the es5-shim does. However, when it comes time to combine modules together into a built file, which is when almond would be used, it is expected that the tool building the file that contains multiple modules will inject names into the define() calls at that time. Otherwise, there is no way for the loader to know how to satisfy the dependency if a module does a require('es5-shim'), and the factory function for es5-shim will never get run. So it does not matter if es5-shim does or does not export a module value, it is just that the loader will not know what functions to call to execute module code without names, when in a built file. If you think there is a way that can be made clearer in the README, I'm open to clarifying it. The main thing though is to use an optimization tool that knows how to insert names for anonymous modules when combining modules together. Built files with a combination of modules is when almond would be used. |
Thank you for your answer. Other requirements were perfectly clear but indeed I missed this one. |
Can I propose that Let's say we optimize all our JavaScript into one file, |
I would not want to silently fail. That will just make the problem harder to find. What I would consider is throwing an error with a specific message about the likely cause. I was hoping to avoid that as it increases the size of the library and is not needed for properly optimized code. |
The other option too is that you can fork the code and provide your own version of the AMD API provider that you prefer. For these smaller AMD providers I encourage that as it allows fine grained control over the type of provider you want. |
My reasoning was that if the call is expected and fails, a little time with the developer tools would easily identify the issue. But yes, it would make the common case a little harder and an uncommon case a lot easier. |
Anyway, thanks for the suggestions. We managed to fix it on our end in the way you describe, just wanted to let you know that this requirement ( |
AMD specifications (https://github.com/amdjs/amdjs-api/wiki/AMD) states that the define function can be called with 1, 2 or 3 parameters, almond only supports 2 or 3 arguments.
The text was updated successfully, but these errors were encountered: