In javascript, I have like.,
0. Current Way of Naming:
Cell = function(position){
//Constructor.
var pos = position;
//Many Sub-functions using variable `pos` here through out this function Cell.
}
But in java/C++, I could write the same as.,
Cell(int pos){
this.pos = pos;
}
Proposed ways of naming :
1. About this.pos = pos
Here in javascript too I could do like this.pos = pos
, it will work. But the problem is.,
then through out the program I have to access my position as this.pos
., and it hazardous when assigning because when I assign like this.Pos = 7
(wrong case), then it wont show bug. So this method is not preferable.
2. About pos = _pos
Cell = function(_pos){
//Constructor.
var pos = _pos;
But generally, in C++/Java I will not use this way, so preferably, this is not my best way.
3. Using the parameter of constructor as variable through the function.
Cell = function(pos){
I could use this pos, through out my function, but I am in doubt whether I could do this. Because, I need to do this in a proper prototype-oriented way with constructors, setter, getter etc... Moreover in the John resign link , he used value
and val
two different names.
In this link., Best practice for parameter naming in Java constructors and simple setters I saw, there is no conventions for parameter naming.
My personal preference is 1, but I will be forced to use, this.pos
and risky too.
So, Is 1 or 2 or 3 or 0 (my current way)., which one is best?