Skip to content

Commit 0898d77

Browse files
Aula 4 - objetos, funcoes, escopos e parametros
1 parent e14e8e5 commit 0898d77

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

Diff for: codigo.js

+46
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,58 @@ function adicionar() {
142142
function testar() {
143143
console.log("1");
144144
let x = 0;
145+
// executa função de forma assíncrona
145146
setTimeout(function () {
146147
x++;
147148
console.log("2");
148149
}, 0);
149150
console.log("3");
150151
}
152+
// criando como class
153+
// class Pessoa {
154+
// constructor() {
155+
// this.cpf = "";
156+
// this.nome = "";
157+
158+
// //arrow function
159+
// const Outra = () => { // não usa a palavra function
160+
// // function Outra() {
161+
// this.printCpf();
162+
// };
163+
164+
// Outra();
165+
// }
166+
// printCpf() {
167+
// console.log("CPF: ", this.cpf); // this: objeto do contexto
168+
// };
169+
// }
170+
171+
// criando como function
172+
function Pessoa() {
173+
this.cpf = "";
174+
this.nome = "";
175+
//arrow function
176+
const Outra = () => this.printCpf()
177+
178+
// não usa a palavra function
179+
// function Outra() { }
180+
Outra();
181+
}
182+
183+
Pessoa.prototype.printCpf = function () {
184+
console.log("CPF: ", this.cpf); // this: objeto do contexto
185+
};
186+
187+
Pessoa.prototype.printNome = function () {
188+
console.log("Nome: ", this.cpf);
189+
};
190+
191+
// metodo != função
192+
function printPorLinha() {
193+
for (let parametro of arguments) {
194+
console.log(parametro);
195+
}
196+
}
151197

152198
// HTTP : HyperText Transfer Protocol - protocolo de transferência de hypertexto
153199

Diff for: index.html

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<a href="#" onclick="transitionTo(event, '/primo')"> Primo</a>
2626
<button onclick="testar()" type="button">Testar</button><br>
2727
<div id="container" class="content conteudo corpo-pagina etc-etc">
28+
2829
</div>
2930
<!-- <div style="position:fixed;top:0;width:100%;height:100%">
3031
LOADER

Diff for: router.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
Math.sqrt(9);
2-
31
function carregarConteudo() {
42
let path = window.location.pathname;
53
let html = "";
6-
switch (path) {
4+
switch (path) { // verifica qual é a rota
75
case "/":
86
html = "formulario.html";
97
break;
@@ -22,22 +20,21 @@ function carregarConteudo() {
2220
// serializa para texto -> container.innerHTML = texto
2321
if (html != "") {
2422
fetch(html) // Promise
25-
.then(function (resposta) { // quando o servidor retornar a resposta HTTP
26-
return resposta.text(); // Segunda Promise
27-
})
28-
.then(function (texto) { // quando a resposta for transformada em string
29-
container.innerHTML = texto;
23+
.then(
24+
// quando o servidor retornar a resposta HTTP
25+
resposta => resposta.text() // Segunda Promise
26+
)
27+
// quando a resposta for transformada em string
28+
.then(function (texto) {
29+
container.innerHTML = texto
3030
});
3131
}
32-
console.log()
3332
}
3433

3534
function transitionTo(event, path) {
3635
event.preventDefault(); // impede que a tag "a" ao ser clicada redirecione a pagina
37-
window.history.pushState("", "", path);
36+
window.history.pushState("", "", path); // troco apenas a url sem redirecionar
3837
carregarConteudo();
3938
}
4039

41-
window.addEventListener("load", function () {
42-
carregarConteudo();
43-
});
40+
window.addEventListener("load", () => carregarConteudo());

Diff for: server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
PORT = 8000
44
class SimpleHandler(http.server.SimpleHTTPRequestHandler):
55
def do_GET(self):
6-
match = re.search("\.(js|ico|html|png|css|map)$", self.path)
6+
match = re.search("\.(js|ico|html|png|css|map)$", self.path) # self é o this em python
77
res = None
88
self.send_response(200)
99
filename = "index.html" if match == None else self.path[1:]

0 commit comments

Comments
 (0)