-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16-callBack-functions.html
More file actions
78 lines (56 loc) · 1.89 KB
/
16-callBack-functions.html
File metadata and controls
78 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>call back functions</title>
</head>
<body>
<script>
//first example for callBack function
//you can pass inside another function as a parameter this is call callBack function.
// function add(a, b, callBack) {
// console.log(a + b);
// callBack();
// }
// function sayHello() {
// console.log("hello every one")
// };
// function sayHI() {
// console.log("its call back function")
// }
// add(5, 8, sayHI)
// add(7, 9, sayHello)
// //using anonymous function (means unknown name)
// add(7, 9, function () {
// console.log("this is anonymous function means without name")
// })
//second example of callBack function using asynchronus:
function loadScript(url, callBack){
let script=document.createElement("script")
script.src=url;
document.body.appendChild(script);
script.onload=function(){
callBack(null,url);
}
script.onerror=function(){
callBack(new Error("src got some error "));
}
}
function onLoad(src){
console.log("script is loded successfully.. " +src)
}
function onError(error,src){
if (error){
console.log(error)
return;
}
else{
console.log("your url run succesfully ")
}
}
loadScript("https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" ,onLoad);
</script>
</body>
</html>