I'm struggling to send a parameter to a function in JavaScript

I've been attempting to incorporate a setTimeout function, but I'm encountering some issues.

setTimeout(myfunction(parameter), 200)

The code above doesn't seem to be working as expected. On the other hand, the following code works fine but it's not accomplishing what I need because I can't pass a parameter. Can someone shed some light on this issue?

setTimeout(myfunction, 200)

Answer №1

Experiment with

setTimeout(function() {
    mycustomFunction(argument);
}, 200)

Alternatively, you have the option to

setTimeout(mycustomFunction.bind(null, argument), 200);

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

Observables waiting inside one another

I've encountered an issue where I need to return an observable and at times, within that observable, I require a value from another observable. To simplify my problem, let's consider the following code snippet: public dummyStream(): Observabl ...

What is the best way to calculate the number of days that have passed since a certain

Hey there, I've got this 10 Dec, 2019T14:07:21 date format from the backend. My goal is to determine how many days ago it was. For example, today is the 20th, so if the date is today's date, it should show as 0 days ago. ...

What exactly is the significance of the code snippet "var data = jQuery(msg), script;" in JavaScript?

this snippet is extracted from a Google Chrome extension "search" == request.ajax && $.ajax({ url: request.url, type: "GET", dataType: "html" }).done(function(msg) { if (msg.indexOf("https://login.testabc.com/ ...

The function was triggered upon the form loading, instead of being activated when the button was clicked

The issue I am facing is that in the code snippet below, the function readCSV() is not being triggered when buttons for filepath1 and filepath2 are clicked. The function is only executed on form load. I was expecting it to work on button click as well. I ...

Struggling to retrieve unpredictable data in a Vue.js component

Help! I'm trying to randomly display one of these names in my HTML, but I can't seem to make it work: Vue.component('modal', { template: '#modal-template', data: { items: [ { name: 'Elena' }, { na ...

Exploring PrimeNG's method for expanding and collapsing groups

I'm attempting to incorporate two buttons that can be used to either expand or collapse all the groups in my code utilizing primeNG. Below is the functioning code: PLUNKER <p-dataTable [value]="data" sortField="room" rowGroupMode="subheader" grou ...

How to Use Fetch API to Send Files Using Form-Data

I've been facing challenges connecting my React frontend to my express and MongoDB backend. While using Postman was successful for testing requests, I encountered issues when trying to use fetch and Axios. Here is the postman request that worked: htt ...

Record changes in another sheet when Google Spreadsheet is edited

Can anyone provide assistance with a problem in Google Spreadsheet? I am looking to log the name and timestamp when a value in a specific column in the "Venues" sheet is changed. However, I'm having trouble determining if I'm working with the co ...

ngBlur functions correctly only when focused element is tabbed out of

When an input field loses focus, I am trying to call a method using ngBlur. This seems to work well when removing focus by pressing the tab button. However, if focus is removed by clicking somewhere else in the form, the ngBlur does not behave as expected. ...

Guide on retrieving file information after transmitting it to another PHP file through Ajax

I have written code to upload a file and send it to a php page. I would like the response to be an array containing information about the uploaded file such as name, size, type, etc. I am using the "POST" method for uploading the file. Is this approach cor ...

Detecting when the page is done loading in CasperJS with the help of $.ajaxStop()

During my CasperJS tests, I've relied on waitForSelector() to check if a page has finished loading, including all asynchronous AJAX requests. However, I'm interested in finding a more standard approach for waiting for page load. Is it possible to ...

Upon refreshing the page, Vuex encounters an issue where it is unable to read

My website has a Navbar component that utilizes values from the Vuex store. Prior to entering each route, I trigger a dispatch from Vuex as shown below: router.beforeEach((to, from, next) => { //... store.dispatch("updateUserData"); ...

streaming an HTML5 video directly from memory source

After retrieving multiple encrypted data using ajax queries and performing necessary manipulations to turn them into a valid video, I find myself at a standstill. The binary of the video is now stored in memory, but I am unsure how to display it. To confi ...

Navigating attributes originating from the key in JSON: A guide to effective management

I'm facing a situation in my application where I have a JSON object structured like this: var pages = { home: { title: "Home", description: "The home page", file: "home.html", url: "/home" }, blog: { ...

Employ an asynchronous immediately-invoked function expression within the callback

Can an asynchronous IIFE be used inside the callback function to avoid the error message "Promise returned in function argument where a void return was expected"? You can find an example here. signIn(email: string, password: string, course?: ICourse): ...

Guide to storing user data retrieved from the LinkedIn API into an Angularjs controller with the help of a personalized service

Hey there, I'm currently diving into Angular and facing a challenge with saving user information from LinkedIn API to the controller's scope without directly passing it to my custom service. It seems like that might not align with the best practi ...

Apply the :after pseudo-class to the specified element

I am struggling with implementing an overlay effect on two images on my website. My goal is to add an overlay when the images are clicked, and I have tried creating this effect using the after pseudo class. Unfortunately, the overlay does not seem to wor ...

I have chosen to use a json file as the data source for the AutoComplete feature, as it allows for quicker loading times on the client side. This approach helps minimize hits to the database. Do you think

Currently, I am utilizing a JSON file as the source for AutoComplete. The JSON file is being downloaded at the client side in order to minimize hits on the database. I'm experimenting with this approach to find the most efficient way. What are your th ...

Guide to clicking on elements with selenium framework

Struggling to scrape a web page from the bookmyshow site using selenium. Encounter two popups upon loading the page, trying to click the necessary buttons to close them. Facing issues locating these elements despite using sleep() to ensure complete page lo ...

The MUI5 drawer overlapping a modal dialog

Is it possible to use MUI5 to open a side drawer on top of a modal dialog that triggers it? Currently, the dialog triggers the side drawer but it opens behind this. It appears as though a modal dialog (drawer) is attempting to open over an already-opened ...