Using this reference for private variables in javascript

Darkstylee

New Member
As I am from background of java, I always have a style of using \[code\]this\[/code\] reference often..For Example...\[code\]class Sample{ private int x; private int y; Sample(int x,int y) { this.x = x; this.y = x; } //Other Code.... }\[/code\]But in JavaScript I read that \[code\]this.x\[/code\] will create an public variable.Hence, to avoid \[code\]this.x\[/code\] in javascript I changed the actual parameter to be \[code\]X\[/code\] instead of \[code\]x\[/code\] in the below javascript. And my javascript works fine.\[code\]Position = function(X,Y){ //Constructor... var x; var y; if(/*condition on X Y */) { x = X; y = Y; } //Other Code here..}\[/code\]But I want to know whether any alter way for having actual parameter name and variable name to be same. ie. like \[code\] Position = function(x,y) { //Constructor... var x; var y; if(/*condition on this.x this.y */) { this.x = x; this.y = y; }\[/code\]
 
Back
Top