We are having an argument, where it has been proposed (among other things) to change requirejs statements like this:
define(['thing', 'xyzzyView', 'backbone'],
function(thing, XyzzyView, backbone) {
...
thing.doStuff();
...
var xyzzyView = new XyzzyView();
...
var myView = new backbone.View(...);
});
to this:
define(['thing', 'xyzzyView', 'backbone'],
function(Thing, XyzzyView, Backbone) {
...
Thing.doStuff();
...
var xyzzyView = new XyzzyView();
...
var myView = new Backbone.View(...);
});
The argument is that you see by the capitalization that something has been imported with requirejs.
I am against the change, as I see capital first letter as something that identifies a constructor function specifically, which I feel is more important to recognise than something that has been imported. I feel that this follows Crockford's line here:
... Most variables and functions should start with a lower case letter.
Constructor functions that must be used with the new prefix should start with a capital letter. JavaScript issues neither a compile-time warning nor a run-time warning if a required new is omitted. Bad things can happen if new is not used, so the capitalization convention is the only defense we have. ...
It can be argued that the backbone variable should have an uppercase first letter, since this occurs in many (most?) examples you find on the net, including backbone's own code. But I feel that this is just poor coding on Backbone's part.
Am I wrong? Is there some third option that might be better here?
lowercase
module names, e.g. Java or Python: reserve CamelCase for classes. (3) Some languages with a module hierarchy tend toCamelCase
package names just like class names, e.g. Perl or Haskell: distinguish modules from variables and functions. (∴) There's no clear precedent, and either reason makes a lot of sense as long as you stay consistent. While I have a clear personal preference, this question is entirely opinion-based. – amon Aug 27 at 12:08