Currently I'm trying to understand source code of Backbone.js and noticed that the main Backbone
property/object is first letter capitalized:
var root = (typeof self == 'object' && self.self === self && self) ||
(typeof global == 'object' && global.global === global && global);
// Set up Backbone appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
root.Backbone = factory(root, exports, _, $);
});
I don't understand why it's not just root.backbone
. I've heard that people name constructors with first letter capitalized but in the case we have factory method.
So, when we aren't dealing with a library and write simple code we don't do such capitalization(as far as I see on the tutorials) and we don't name objects which were created with constructors in such way:
var person = new Person("John", "Doe", 50, "blue") //not var Person
I think the answer to the question can help a lot of newcomers to understand js script code.