When writing methods for a class, I generally use the following pattern: [1] ``` /** * APIdox */ function doSomething() { } this.doSomething = doSomething; ``` instead of [2]``` /** * APIdox */ this.doSomething = function() { }; ``` I prefer to do this even if `doSomething` is never used internally in the class. This is because if and when it becomes necessary to use this function within the class, I do not need to change too many lines by switching from [2] to [1]. I am also more comfortable with the C++ pattern in which public functions are expected to be simply callable just like a private function within the class. It would be nice to have a policy for this so we can have a consistent style. Thoughts?
On 24 March 2014 22:50, Aditya Bhatt
I prefer to do this even if `doSomething` is never used internally in the class. This is because if and when it becomes necessary to use this function within the class, I do not need to change too many lines by switching from [2] to [1].
I'm not terribly bothered either way. I'm slightly allergic to future-proofing things, but following this pattern doesn't introduce too many unnecessary lines. -- Philip Peitsch Mob: 0439 810 260
participants (2)
-
Aditya Bhatt
-
Philip Peitsch