Linked Questions
38 questions linked to/from JavaScript: Passing parameters to a callback function
4
votes
2
answers
216
views
Javascript: How to pass a callback with intended argument [duplicate]
I want to print a string of my choice to the console after 2 seconds.
This prints 'Hello' to the console after 2 seconds:
function log() {
console.log("Hello")
}
t = setTimeout(log, 2000)
But I ...
3
votes
3
answers
406
views
Passing a parameter to a callback function [duplicate]
I needed to pass a parameter to a callback function in Javascript, so I did the following which creates an anonymous function as a string and then passes it:
var f = "var r = function(result) {...
-2
votes
1
answer
137
views
How to pass parameter to callback in javascript [duplicate]
I would like to pass some parameter in call back like the following example. Is it a possible? Or I need to do it in another way?
function testCallback(callback, destination){
// how can I pass ...
0
votes
1
answer
73
views
JavaScript how to create inner function with function as an argument without imidietly invoking it? [duplicate]
I tried this but it's immediately invokes addClass after opening website :
function onMouseOver(element, event) {
element.addEventListener("mouseover", () => {
event
})
}
onMouseOver(...
0
votes
1
answer
59
views
Handle Event and define parameter after event parameter in javascript [duplicate]
let testTime = document.querySelectorAll(".testTime"); // this List has 3 value. 30, 60, 120
testTime.forEach((x) => {
console.log(x.innerHTML);
addEventListener("click",...
0
votes
0
answers
30
views
How can I pass some additional variables to a replacement function in JavaScript? [duplicate]
I have this structure
function foo() {
var obj = [];
var text = '...';
text = text.replace(/.../g,matching_fn);
}
function matching_fn($match, $match1, $match2) {
// i need obj here
}
...
0
votes
0
answers
20
views
JavaScript Pass Parameter to Callback [duplicate]
I'm working with a JavaScript library, and it takes callbacks as a parameter to functions, that execute when the function is completed. So, for instance, I have something like:
bot.dig(target, ...
56
votes
5
answers
47k
views
Pass an extra argument to a callback function
I have a function callWithMagic which takes a callback function as a parameter and calls it with one argument.
const callWithMagic = callback => {
const magic = getMagic();
callback(magic);
};
...
11
votes
4
answers
18k
views
Pass additional parameter to Javascript callback function [duplicate]
I need to watch a small number of directories in a Node.JS application:
function updated(event, filename){
log("CHANGED\t/share/channels/" + filename);
}
for(i in channels)
fs.watch('share/...
19
votes
2
answers
54k
views
Passing parameters to a callback function using arrow function
I know this is a duplicated question with ES5, but I am looking for the syntax with ES6 arrow function. My code below:
fetchItems = (callback) => {
//After ajax success
callback(response);
...
9
votes
2
answers
11k
views
Javascript: how to pass parameters to callback function [duplicate]
I'm stumped on how to correctly pass parameters to a callback function without immediately calling that function.
For example, this will work as expected:
var callBack = function() { ... }
window....
5
votes
5
answers
5k
views
Add additional parameters to callback function
I'm building a system in Node.js that is supposed to find all files in an array of folders, stat them, and then do some additional work using that information.
I'm using fs.readdir() to get all the ...
0
votes
4
answers
3k
views
How arguments are passed in callback functions?
I had started to learn JavaScript for web development and I am currently stuck at a point in the callback function. The problem is that I can't understand how arguments are passed in JavaScript.
CODE:
...
2
votes
4
answers
4k
views
Javascript callback function with parameter?
I have this simple code :
console.log('calling doWork func...')
doWork('a', 'b', myCb);
function doWork(param1, param2, callback)
{
console.log('in func')
callback();
}
function ...
-1
votes
2
answers
2k
views
synchronous ajax call - show div before call
I need to make a div that covers my entire screen be displayed before an sync ajax call.
But it seems that absolutely nothing I try to do causes the DOM to be modified to show this div before the ...