JavaScript object which can be called

Advertisements

I am trying to create a function which can be invoked through the following ways:

log() 
log.error()

Based on my understanding, we can creating such a function by writing on the function itself:

function log(){

}
log.error = () => {}

is it not recommended writing on the function this way? Because JavaScript might release an update in the future which might hold the "error" property, then my "error" property will be overriding this JavaScript feature.

>Solution :

It’s very unlikely that ECMA spec will add a .error property to function objects.

Leave a Reply Cancel reply