-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncoes_callback.html
More file actions
36 lines (28 loc) · 995 Bytes
/
funcoes_callback.html
File metadata and controls
36 lines (28 loc) · 995 Bytes
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript - Funções de callback</title>
<script>
function exibirArtigo(id, callbackSucesso, callbackErro) {
//lógica: recuperar o id via requisição http
if(true) {
callbackSucesso('Funções de callback em JS', 'Funções de callback são muito utilizadas...')
} else {
callbackErro('Erro ao recuperar os dados')
}
}
var callbackSucesso = function(titulo, descricao) {
document.write('<h1>' + titulo + '</h1>')
document.write('<hr />')
document.write('<p>' + descricao + '</p>')
}
var callbackErro = function(erro) {
document.write('<p><b>Erro:</b>' + erro + '</p>')
}
exibirArtigo(1, callbackSucesso, callbackErro) //estamos passando a variável e não a função. Pois não queremos executar a função ao chamá-la, apenas referenciar para que ela possa ser acessada.
</script>
</head>
<body>
</body>
</html>