Callback function

Developer
Size
2,939 Kb
Views
12,144

How do I make an callback function?

Callback functions tutorial and testing stuff. What is a callback function? How do you make a callback function? This script and codes were developed by Paul on 27 October 2022, Thursday.

Callback function Previews

Callback function - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>callback function </title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div> <button type="button" id="button">call to cation</button>
</div>
<div id="addContent"> Is:
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Callback function - Script Codes CSS Codes

div{ margin:15px 30px;
}
button{ height:50px; width: 100px; background-color: #ff6687;
}

Callback function - Script Codes JS Codes

//var element = document.getElementById('button');
//nutze jquerxy anstatt vanilla js
/*
//lesson 1
$('#button').click(function () { alert("Btn was clicked");
});
//lesson 2
var list = ["Milk", "Butter", "Eggs", "Cake", "Coffe"];
list.forEach(function(eachName, index){ console.log(index+1+". "+eachName);
}); */
//lesson 3
// durchreichen & global scope erreichen
var allUserData = [];
var generalLastName = "Simpson";
var clientData = { id: 058152014, fullName: "not Set", setUserName: function(firstName, lastName){ this.fullName = firstName + " "+ lastName; }
}
function logFoo(userData){ if(typeof userData === "string") { console.log(userData); } else if(typeof userData === "object") { for (var item in userData){ console.log(item+": "+userData[item]); } }
}
function getInput (options, callback){ if(typeof callback === "function") { allUserData.push(options); callback(/*generalLastName,*/ options); }
}
/*
//geht nicht wegen call und apply
function getUserInput(firstName, lastName, callback){ callback(firstName, lastName);
}
*/
//hier nun mit apply
/*
function getUserInput(firstName, lastName, callback, callbackObj)
{ callback.apply (callbackObj, [firstName, lastName]);
}
/*
getInput({name: "Hulk", powers: "is green"}, logFoo);
getInput({name: "ironman", madeOf: "iron"}, logFoo);
getInput({name: "deathpool", height: "1''70", race : "soldier", alignment : "true neutral"},logFoo);
getInput("durchgereichter string", logFoo);*/
//getUserInput("Pitty", "Platsch", clientData.setUserName, clientData);
//console.log(clientData.fullName);
// handle callbacks mit AJAX
/*
function successCallback(){ console.log("successMessage");
}
function completeCallback(){ console.log("completeMessage");
}
function errorCallback(){ console.log("errorMessage");
}
$.ajax({ //url: "https://fiddle.jshell.net/favicon.png", //schmeisst eine error und eine complete, weil codepen hier nicht zugreifen darf //placekitten hingegen, gibt eine successmeldung url: "http://placekitten.com/g/150/150", success: successCallback, complete: completeCallback, error: errorCallback
});
*/
function gedichtMacher(name, gender)
{ console.log(name+" ,deutlich besser als der Schnitt."); console.log("Großherzig, loyal und auch verrückt"); console.log("Als "+gender+" stark und nie am schwächeln.") console.log("Meistert Probleme mit einem Lächeln.")
}
function getUserInput(firstName, lastName, gender, callback)
{ var fullName = firstName + " "+lastName; if(typeof callback === "function"){ callback(fullName, gender); }
}
getUserInput("Robert", "Eichie", "Mann", gedichtMacher);
//ternäres if
function greetUser(customerName, sex)
{ var salutation = sex && sex === "Man" ? "Mr." : "Ms."; console.log("Hello, "+salutation+" "+customerName+".");
}
//cool wie getUserInput auf verschiedene anderee Funcktionen benutzt werden kann, und nicht extra nochmal angepasst werden muss
getUserInput("Kermit", "Frosch", "Man", greetUser);
Callback function - Script Codes
Callback function - Script Codes
Home Page Home
Developer Paul
Username paulq
Uploaded October 27, 2022
Rating 3
Size 2,939 Kb
Views 12,144
Do you need developer help for Callback function?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Paul (paulq) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!