Using CoffeeScript to pass a method into SetTimeOut

Here is my CoffeeScript snippet:

setTimeout (-> @checkProgress()), 5000   

After executing this code in the browser, I encountered the following error message:

TypeError: this.checkProgress is not a function

The actual method implementation looks like this:

checkProgress: ->
    ~ code
    ~ code
    ~ code
    setTimeout (-> @checkProgress()), 5000   

I need to figure out how to call the method again at some point. Any suggestions would be appreciated. Thanks.

Answer №1

setTimeout executes the @checkProgress function within the window context. To achieve this, use a fat arrow function:

setTimeout(() => @checkProgress, 5000)

Answer №2

This method worked flawlessly for me too.

repeat = =>
          @verifyCompletion()
        setTimeout repeat, 5000

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS dynamically updates the minimum date in a datepicker

My controller dynamically sets a minimum date which I retrieve as 'setmax'. I want to assign this value to my datepicker mindate. I have attempted to do this by using the following code: $scope.minDate = $scope.setmax; inside my controller. U ...

Is there a way to implement Method Chaining in JavaScript?

I am trying to chain these two method calls together: utils.map([1,2,3,4,5], function (el) { return ++el; } ) and utils.filter(function (el) {return !el%2; } While both methods work fine individually, the following chained code is not functioning corr ...

What is the best way to implement promise function in a JavaScript functional method such as forEach or reduce?

I have implemented a promise function in the following way: // WORK let res = {approveList: [], rejectList: [], errorId: rv.errorId, errorDesc: rv.errorDesc}; for (let i = 0; i < rv.copyDetailList.length; i ++) { const item = rv.copyDetailList[i]; ...

Using PHP to pass values from a MySQL database to JavaScript

hello, $i=0; while($row = $result->fetch_assoc()) { echo " <tr><td>".$row["Number"]."</td><td>".$row["MusikName"]." ".$row["MusikURL"]."</td></tr>"; This portion is successful...it displays -&g ...

Is there a way to implement a particular CSS style based on a user's selection in a checkbox?

Is there a way to implement specific CSS code based on user choices made in checkboxes? I need the CSS to change dynamically according to what the user selects. For example: If Platform = Unix, Windows, and Network are selected, execute the CSS for Unix ...

What is the best way to incorporate a N/A button into the dateRangeFilter located in the header of a webix dataTable, enabling the exclusion of N/A values within that specific column?

`webix.ready(function(){ grid = webix.ui({ container:"tracker", editaction:"click", editable:true, view:"datatable", css:"webix_header_border", leftSplit:1, ...

Ensure that the page is edited before being shown in the iframe

Is it possible to remove a div from an HTML page within an iFrame? The code below fetches an HTML page and displays it in an iframe. Is there a way to remove the specified div from the fetched HTML page? <script type="text/javascript"> (function(){ ...

Tips for managing errors when using .listen() in Express with Typescript

Currently in the process of transitioning my project to use Typescript. Previously, my code for launching Express in Node looked like this: server.listen(port, (error) => { if (error) throw error; console.info(`Ready on port ${port}`); }); However ...

Is it possible to achieve Two-Way Binding in a custom directive without relying on NgModel?

I am creating a custom dropdown without using any input element or ngModel for two-way binding. Is it possible to achieve two-way binding with custom attributes? var mainApp = angular.module('mainApp', []); mainApp.directive('tableDropdo ...

Error encountered when referencing iscrollview and iscroll js

Greetings! I am new to the world of JavaScript and jQuery, currently working on developing a phonegap application. As part of my project, I am exploring the implementation of the pull-to-refresh feature using iscroll and iscrollview as demonstrated on & ...

Executing PHP code on button click in HTMLThe process of running a PHP script when

I am currently working on a project that involves detecting facial expressions using Python. However, I need to pass an image to this code through PHP. The PHP code provided below saves the image in a directory. How can I trigger this code using an HTML ...

Website errors appear on the hosted page in <body> section without being present in the code

Hello there, I have set up a debug website using my "Olimex ESP-32 POE" to send internal data via JSON, eliminating the need for Serial Output from the Arduino IDE (the reasons behind this are not relevant). #include "Arduino.h" #include <WiF ...

Is it possible to match a field with an array field in a query?

Imagine having a collection structured like this: { film : 1, Items : [ 1 , 2 ,5 , 6 ] }, { film : 2, Items : [ 3, 5, 7 ] }, { film : 3, Items : [ 1, 3, 6 ] } I am looking to retrieve all entries where the 'film' is included i ...

Update the div each time the MySQL table is refreshed

My website functions as a messaging application that currently refreshes every 500ms by reading the outputs of the refresh.php file. I'm looking to explore the possibility of triggering the refresh function only when the 'messages' table upd ...

When errors occur while printing HTML through an Ajax request, it can hinder the functionality of other JavaScript code

I recently conducted an interesting experiment on my website. The concept involved sending an AJAX request to a PHP file, which then retrieved a random website by using various random words for search queries on Google. The retrieved website content was th ...

retrieve the data-task-IDs from the rows within the table

I am currently working with a table that looks like this: <table id="tblTasks"> <thead> <tr> <th>Name</th> <th>Due</th> ...

Create a Promise that guarantees to reject with an error

I am relatively new to utilizing promises, as I typically rely on traditional callbacks. The code snippet below is from an Angular Service, but the framework doesn't play a significant role in this context. What really matters is how to generate a pro ...

Guide to naming Vite build JS and CSS bundles in Vue

As I work on building a SPA using Vite+Vue3 and JavaScript, I have encountered an issue when running npm run build. After making changes, the resulting .css and .js files have names that appear to be generated from a hash, which is not ideal. I would like ...

Waiting for the asynchronous fetch operation to finish in a webpacked application block

Currently, I am facing an issue where I need to block the fetching of an external JSON file so that a configuration object can be consumed elsewhere. This process involves three files: builder.jsx runtime.jsx and a JSON file: config.settings.json In t ...

Organize elements with jQuery, remove, detach, clone, and append without worrying about memory leaks

I am facing a challenge with a parent div that contains approximately 300 child divs, each one containing an image and some text. I have an array with the necessary information to reorder these divs using references. However, whenever I loop through the a ...