-
March 9th, 2010
JavaScript Naming Conventions For People With Beards
When developing in a team environment, coming to an agreed-upon set of naming conventions is incredibly important. The speed at which we as developers can come to comprehend the thought-processes and intentions of our peers greatly depends on our ability to look straight to their intentions, rather than having to first read the code line by line, mentally translating it into our own dialect, before truly understanding.In short, Aaron Cruz, here is a quick summary of the naming conventions which I adhere to:
var MyClass = Class.create({ initialize: function(arg1, arg2) { this.publicProperty = "'Public' property"; this._privateProperty = "'Private' property"; var localVariable = null; }, publicMethod: function() { return "'Public' method"; }, isBooleanMethod: function() { return true; }, _privateMethod: function() { return "'Private' method"; }, __eventHandlerMethodClick: function(e) { return "Click-event handler method"; } }); MyClass.classProperty = "Class-level property"; MyClass.classMethod = function() { return "Class-level method"; }; MyClass.MY_CLASS_CONSTANT = "CONSTANT's should never change"; MyClass.ClassEnumOrSubType = { value0: 0, value1: 1, value2: 2, value3: 4, value4: 8 };While the above example uses the Prototype class structure, none of the principles themselves are Prototype-specific.