Can classes in es6 call their own methods?

I want to initialize this.detailImgUrls with concatImgUrls () when initializing the object. Which of the following methods should I use?

function concatImgUrls() {
    return "haha";
}

export default class Car{
    constructor(data){
        this.address = data.address;
        this.displacement = data.displacement + "L";
        
        this.detailImgUrls = concatImgUrls();

    }
}
export default class Car{
    constructor(data){
        this.address = data.address;
        this.displacement = data.displacement + "L";
        this.detailImgUrls = this.concatImgUrls();

    }

    concatImgUrls() {
        return "haha";
    }


}

I tried both, but in the second case, the object method is supposed to be used by the instantiated object, not in the class.

Es6
Apr.01,2021

how es6 is implemented, prototype chain, the reason is known

use is self-determined, and every strongly typed language is not limited to death

Menu