Is this a right way to set a variables as private?
function test(a, b){
let aa = a
let bb = b
return {
getA: () => {
return aa
},
getB: () => {
return bb
}
}
}
Now I can't access aa
and bb
directrly. And if I put this
keyword infront of the variables, will it be accepted as an object? I know that in JavaScript functions are objects but it become more like object syntax. I am confused a lot from all the JavaScript options. It seems like there is no conventions in anything.
The this
type:
function test(a, b){
this.aa = a
this.bb = b
return {
getA: () => {
return this.aa
},
getB: () => {
return this.bb
}
}
}
Both examples seems equal to me. The summed question - Is the privace of those variables is achieved in those ways ?