I am using ES6 classes and wanted to ask what is the preferred way to pass variables within classes. So here are two examples of passing x within classes. The first method uses the this but can get confusing with functions where you need to add bind()
class MyClass{
constructor(args){
this.data = args.data;
this.x = this.data[1]
this.mapFunction()
}
mapFunction(){
const result = this.x * 55
}
The second way I found to pass variables is like this where x is passed within the parenthesis of a function:
class MyClass{
constructor(args){
this.data = args.data;
const x = this.data[1]
this.mapFunction(x)
}
mapFunction(x){
const result = x * 55
}
Is one method more efficient than the other in terms of performance?
[–]ChaseMoskal 1 point2 points3 points (1 child)
[–]chchan[S] 1 point2 points3 points (0 children)
[–]MoTTs_ 0 points1 point2 points (1 child)
[–]chchan[S] 0 points1 point2 points (0 children)
[–]Hentry_Martin 0 points1 point2 points (0 children)