[WebODF] Functions/Methods in a class

Aditya Bhatt aditya at bhatts.org
Mon Mar 24 12:50:15 CET 2014


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?


More information about the WebODF mailing list