Pmmoks Pmmoks - 3 months ago 8
Javascript Question

Basic query about chain functions

Pretty basic question but, in a case like this...

const myVariable = GenericObject.myMethod().brand.toUpperCase()


what would the
.brand
be referring to...i.e. how does this 'chain function' actually fit together?

You can assume
myMethod
returns an empty object.

Thanks

Answer

It could be something like this

function GenericObject() { }

GenericObject.myMethod = function () {
    return {
        brand: 'string'
    };
}

console.log(GenericObject.myMethod().brand.toUpperCase());

Or

var GenericObject = {
    myMethod: function () {
        return {
            brand: 'string'
        };
    }
};

console.log(GenericObject.myMethod().brand.toUpperCase());