-
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.
Aaron | March 11, 2010 4:12 pm
check this out. another way to deal with private/public methods/variables in javascript without the overhead of a framework. I still haven’t tried it out so…
http://jonaquino.blogspot.com/2009/08/public-and-private-methods-in.html
I logged out of google and twitter to make sure you weren’t using an API to put my name up there. I’m still not sure, kinda spooky.
I guess that I have to write something interesting now…
Aaron | April 29, 2010 1:18 pm
wait a minute here.
so regular obj properties are camelcase
and objects Start with caps?
event handlers have double _
and private methods have single _
do you differentiate between simple vars and arrays?
and the boolean method?
WTF is going on?
Dan Dean | April 30, 2010 8:56 am
Hi Aaron! It actually makes collaborating on code much easier. See: http://dandean.com/category/javascript/2009/on-the-challenge-of-developing-javascript-within-a-team/