Skip to content

Commit c521666

Browse files
committed
Ejemplos sobre "Advanced Functions"
1 parent 6081802 commit c521666

File tree

8 files changed

+127
-0
lines changed

8 files changed

+127
-0
lines changed

2023-03-09/advanced-functions.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
const suma = function (a, b) {
3+
console.log(a + b);
4+
};
5+
6+
(suma)(5, 6);
7+
// 1. Obtener lo que haya en 'suma'
8+
// 2. Una vez tengo la función: la llamo.
9+
10+
const adiciona = suma;
11+
adiciona(15, 25);
12+
13+
const fabrica = function (x) {
14+
return function () {
15+
console.log(`fabrica ${x}`);
16+
}
17+
};
18+
19+
(fabrica(7))();
20+
21+
const A = [
22+
function (a, b) { return a + b; },
23+
function (a, b) { return a - b; },
24+
function (a, b) { return a * b; },
25+
];
26+
27+
for (const f of A) {
28+
console.log(f(5, 7));
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

2023-03-09/arrow-functions.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fsuma = function (a, b) {
2+
return a + b;
3+
};
4+
const asuma = (a, b) => a + b;
5+
6+
const funcArray = [(a, b) => a + b, (a, b) => a - b, (a, b) => a * b];
7+
8+
const menor = (a, b) => a < b;
9+
const adams = () => 42;
10+
const id = (x) => x;
11+
12+
adams();
13+
menor(1, 3);
14+
id("hola");
15+
16+
const showTwoLines = () => {
17+
console.log("line 1");
18+
console.log("line 2");
19+
};
20+
21+
const makePerson = (name, age) => ({
22+
type: "Person",
23+
name,
24+
age,
25+
});
26+
27+
console.log(makePerson("James", 27));

2023-03-09/make-counter.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
const makeCounter = () => {
3+
let count = 0;
4+
return () => {
5+
count++;
6+
return count;
7+
}
8+
};
9+
10+
let c1 = makeCounter();
11+
console.log(c1());
12+
console.log(c1());
13+
console.log(c1());

2023-03-09/methods.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
const saluda = function () {
4+
console.log(`Hola, soy ${this.name}, qué tal!`);
5+
}
6+
7+
let person = {
8+
name: "James",
9+
saluda,
10+
};
11+
12+
person.saluda(); // left-object ('person')
13+
saluda(); // NOO left-object

2023-03-09/scopes.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
let x = 3;
3+
4+
{
5+
let x = 7;
6+
x++;
7+
console.log(x);
8+
}
9+
10+
console.log(x);
11+
12+
function suma(a, b) {
13+
return a + b;
14+
}
15+
16+
suma(3, 5);

2023-03-09/unbinding.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
let carol = {
3+
name: "Carol",
4+
sayHi: function () {
5+
console.log(`Hi, I'm ${this.name}, how are you?`);
6+
},
7+
};
8+
9+
let sayHi = carol.sayHi;
10+
let carolSayHi = sayHi.bind(carol);
11+
12+
carolSayHi();
13+
14+
let bella = {
15+
name: "Bella",
16+
sayHi: carolSayHi,
17+
};
18+
// No left-object
19+
bella.sayHi();
20+
21+

2023-03-09/use-strict.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
function showMeThis() {
4+
console.log(this);
5+
}
6+
7+
showMeThis();

0 commit comments

Comments
 (0)