Add support for CommonJS implementations that do not support modules.expo#335
Add support for CommonJS implementations that do not support modules.expo#335tonylukasavage wants to merge 2 commits intojashkenas:masterfrom tonylukasavage:patch-1
Conversation
There was a problem hiding this comment.
Best to use typeof exports != 'undefined' here...exports != undefined will throw an exception if exports isn't declared.
There was a problem hiding this comment.
Fixed this in the below commit
|
So, this proposed patch isn't really the same thing as the existing Node.js export. With the current version, you write: With your version, you would have to write: Do you have any facility in Titanium for setting the exports object so that the former will work? Are you planning to introduce a "module" object? |
|
As far as I can tell, |
|
Oh, certainly -- but having to require it in two different ways, depending on the flavor of CommonJS ... is the kind of thing that CommonJS is supposed to fix. Ideally Titanium does (or will) provide a way to set the exports object directly for libraries that export a single object. |
|
|
|
Maybe I'm missing something, but couldn't this be fixed simply by attaching all properties of |
|
@DomenicDenicola ;) You're missing something: https://github.com/documentcloud/underscore/blob/master/underscore.js#L49 Underscore is a function, not just an object. @tonylukasavage -- Unfortunately, the CommonJS "spec" has been dead in the water for a long time now. (Just my opinion, but ...) Regardless of what the spec does or doesn't do at some time in the future, would you consider adding some mechanism to export a single object/function, like Underscore? I don't much mind if it's |
|
Doh! Yes, CommonJS Modules/1.1.1 has sadly failed to provide a way to export functions. I've got my own feelings on that whole kerfluffle, but I'll stand back and let the OP take over from here so as to avoid any further blunders :) |
|
@jashkenas - That may happen at some point, but in the meantime would it not be beneficial to underscore.js to support CommonJS implementations that follow the spec? It's a pretty unobtrusive modification that would make its adoption much easier. |
|
Sure, perfect being the enemy of the good and all that. |
|
@jashkenas - So whadda ya say? We'd love to start encouraging Titanium devs to use this library. |
|
Yep -- I've merged in your change with a tweak. Off topic, but aren't there still problems with Titanium devs trying to use Underscore, due to Underscore not following JSLint rules? Or has that changed recently? |
|
JSLint is an optional validation method with Titanium builds, and not the default one. it's only really an issue if the developer makes it one. |
|
I think that If you're complaining about not wanting to use |
|
@tylermwashburn Yes, it does that. |
|
@jashkenas So it does. I probably should've checked about that first. |
|
FYI, we have an open issue against not being able to assign variables directly to the exports object. There's some discussion as to whether or not it is provided for in the spec - probably it is not, as it would be a liberal reading of the spec document. But we still need to have something. |
Add support for CommonJS implementations that do not support modules.exports.
In its current state we cannot load underscore as a module in Titanium since we do not support the
module.exportsobject. Adding_to the standardexportsobject would expose underscore in a similar modular fashion, and could be used in our apps like this:var _ = require('underscore')._;