Answer the question
In order to leave comments, you need to log in
Code as javaScript function parameters?
Hello.
I foresee the answer that I searched badly in Google.
But at least I tried :)
I want to write a function that will take 2 parameters:
1. variable(s)
2. Javascript code.
So that for example I could call my function like this:
fun1("Hi", function(data) {
here any number of lines of JavaScript code
and would be executed only after the work is completed or the result of
the fun1 function has arrived
});
I'll never know how to do it ...
Tell me or point your finger at the theory so that it's clear :)
thanks in advance!
Answer the question
In order to leave comments, you need to log in
That is, it is necessary that the function be called only after the parent function has been executed? Well, it's unlikely.
Could be something like this:
(function(data) {
dosomething();
})(data = fun1("Привет"));
You asked yourself, you answered...
function fun1(d, f){
//code
f(d);
}
fun1("Привет", function(data){
alert(data);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question