Domanda

I found in requirejs-text plugin weird code. So load method accepts onLoad callable which is invoked for a few times as onLoad(), but later there is error handler which checks for an error method.

if (onLoad.error) {
    onLoad.error(err);
}

Am i missing something or it's obvious code issue?

È stato utile?

Soluzione

You cannot use a normal object as a callable entity, but a function is a type of object, so you can add properties to a function.

var onLoad = function(){

};

onLoad.error = function(){

};
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top