The error encountered in the Lightning component when using setTimeout: “Bind must be invoked on a function.

In our complex application’s component controller, the following code was present:

window.setTimeout(helper.hideSpinner(component, helper), 500);

The functionality is operational; however, it generates an error message that is shown at the bottom of the page.

A function must have ‘bind’ invoked on it.

Solution

Resolution

  1. If set timeout modifies any attributes, use $A.callback
 window.setTimeout(
     $A.getCallback(function() {
         helper.hideSpinner(component, helper)
     }), 
     500
 );

2 . As per setTimeout documentation, use any one of the following if calling function doesn’t modifies any attributes:

window.setTimeout(
     function() { 
         helper.hideSpinner(component, helper)}, 
     500
 );        

 // or send function and arguments separately 
 window.setTimeout(
     helper.hideSpinner, 
     500, component, helper
 );

I conducted an online search but could not locate any related issues. We invested several hours in identifying the root cause, primarily due to the lack of clarity in the error message, at least from our perspective. I am sharing this information here in case someone else encounters a similar problem and gets stuck.