“Rückruf in JS” Code-Antworten

Rückruffunktion JS

function greeting(name) {
  alert('Hello ' + name);
}

function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

Rückruf in JavaScript

function sum(num1,num2,callback){
    let total = num1 + num2
    callback(total)
}

sum(10,20,function(total){
    // received total here
    console.log(total);
})

sum(5,16,(total)=>{
    console.log(total);
})
CodePadding

So erstellen Sie die Rückruffunktion JavaScript

function startWith(message, callback){
	console.log("Clearly written messages is: " + message);
  
  	//check if the callback variable is a function..
  	if(typeof callback == "function"){
    	callback(); //execute function if function is truly a function.
    }
}
//finally execute function at the end 
startWith("This Messsage", function mySpecialCallback(){
	console.log("Message from callback function");
})
Outstanding Lioncatcher

Beispiel für die Rückruffunktion in JavaScript

<html>  
<head>  
  
</head>  
<body>  
<h1>Hello User</h1>  
<h2> This is the softhunt.net</h2>  
<script>  
function showData(name, amt) {  
alert(' Hello ' + name + '\n Your entered amount is ' + amt);  
}  
  
function getData(callback) {  
var name = prompt(" Welcome to the softhunt.net \n What is your name?");  
var amt = prompt(" Enter some amount...");  
callback(name, amt);  
}  
  
getData(showData);  
</script>  
</body>  
  
</html>
Outrageous Ostrich

JS -Rückruffunktion

const add = (num1, num2) => num1 + num2;

const result = (num1, num2, cb) => {
  return "result is:" + cb(num1, num2);
}

const res = result(12, 13, add);
Scary Stag

JavaScript unter Verwendung einer Rückruffunktion

// Callback Function Example
function greet(name, myFunction) {
    console.log('Hello world');

    // callback function
    // executed only after the greet() is executed
    myFunction(name);
}

// callback function
function sayName(name) {
    console.log('Hello' + ' ' + name);
}

// calling the function after 2 seconds
setTimeout(greet, 2000, 'John', sayName);
SAMER SAEID

Ähnliche Antworten wie “Rückruf in JS”

Fragen ähnlich wie “Rückruf in JS”

Weitere verwandte Antworten zu “Rückruf in JS” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen