javascriptrequirejsrequirejs-text

Is it possible to use object as invokable?


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?


Solution

  • 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(){
    
    };