Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

How to use a variable in in an object in a javascript class ?

By M.K. Verma · 3 May 2022

How to use a variable in in an object in a javascript class ?

Remove functions:

 

class Example{

    constructor(something){
        this.something = something;
    }

    foo(){

        return this.something
    }
}

const object = new Example("among")

console.log(object.foo())