Callback function
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 - 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);
Developer | Paul |
Username | paulq |
Uploaded | October 27, 2022 |
Rating | 3 |
Size | 2,939 Kb |
Views | 12,144 |
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!
Name | Size |
Canvas tutorial | 2,043 Kb |
Sticky header | 2,309 Kb |
Keyframes and Webkits with LESS | 2,630 Kb |
TabContainer pure css3 | 2,769 Kb |
A Pen by paul | 1,441 Kb |
A Pen by paul | 2,390 Kb |
Three js | 2,353 Kb |
Parallax on scrollevent | 2,386 Kb |
Flexbox-Slider-Test | 1,666 Kb |
Setter getter closure functions | 1,662 Kb |
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!
Name | Username | Size |
Transition | Shayhowe | 1,632 Kb |
Beautiful canvas stars | Matths | 2,399 Kb |
Simple personal profile | Miroot | 2,856 Kb |
Flexbox slider | Rendro | 3,459 Kb |
Lazy Load for Background Images | The_ruther4d | 2,977 Kb |
Boxes | H3l1um | 2,563 Kb |
Vue Transition | Chenming142 | 4,561 Kb |
CSS Gem Badge | Orchard | 3,335 Kb |
SVG Scalable Text | Said_FD | 1,451 Kb |
Easing | GreenSock | 2,043 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!