jeudi 19 août 2021

How has chalk.green.bold("Some Text") and chalk.bold.green("Some Text") been coded in the background in the npm package chalk

I was recently using the chalk package while learning node. I tried using both chalk.green.bold() as well as chalk.bold.green() and got the same result. I like how it has been implemented where green is being used as both an object as well as a method. So to simplify my question how can you have a variable named say var and have the same output for

    var.x.y.z()
    var.y.x.z()
    var.z.x.y()
    ...

all of these without explicitly defining functionality for them all? What design pattern is used(if any is used in this case)?

Aucun commentaire:

Enregistrer un commentaire