Skip to content

Commit 9da9e2c

Browse files
authored
Merge branch '1.4.4' into master
2 parents fbab595 + 6feb357 commit 9da9e2c

File tree

11 files changed

+251
-247
lines changed

11 files changed

+251
-247
lines changed
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
**Answer: an error.**
1+
**Odpověď: chyba.**
22

3-
Try it:
3+
Zkuste to:
44
```js run
5-
function makeUser() {
5+
function vytvořUživatele() {
66
return {
7-
name: "John",
8-
ref: this
7+
jméno: "Jan",
8+
odkaz: this
99
};
1010
}
1111

12-
let user = makeUser();
12+
let uživatel = vytvořUživatele();
1313

14-
alert( user.ref.name ); // Error: Cannot read property 'name' of undefined
14+
alert( ivatel.odkaz.jméno ); // Chyba: Nelze načíst vlastnost 'jméno' objektu undefined
1515
```
1616

17-
That's because rules that set `this` do not look at object definition. Only the moment of call matters.
17+
Je to proto, že pravidla, která nastavují `this`, se nedívají do definice objektu. Záleží jen na okamžiku volání.
1818

19-
Here the value of `this` inside `makeUser()` is `undefined`, because it is called as a function, not as a method with "dot" syntax.
19+
Zde je hodnota `this` uvnitř `vytvořUživatele()` `undefined`, protože tato funkce je volána jako funkce, ne jako metoda „tečkovou“ syntaxí.
2020

21-
The value of `this` is one for the whole function, code blocks and object literals do not affect it.
21+
Hodnota `this` je stejná pro celou funkci, bloky kódu a objektové literály ji neovlivňují.
2222

23-
So `ref: this` actually takes current `this` of the function.
23+
Takže `odkaz: this` vezme ve skutečnosti aktuální `this` této funkce.
2424

25-
We can rewrite the function and return the same `this` with `undefined` value:
25+
Můžeme funkci přepsat a vrátit stejné `this` s hodnotou `undefined`:
2626

2727
```js run
28-
function makeUser(){
29-
return this; // this time there's no object literal
28+
function vytvořUživatele(){
29+
return this; // tentokrát tady není objektový literál
3030
}
3131

32-
alert( makeUser().name ); // Error: Cannot read property 'name' of undefined
32+
alert( vytvořUživatele().jméno ); // Chyba: Nelze načíst vlastnost 'jméno' objektu undefined
3333
```
34-
As you can see the result of `alert( makeUser().name )` is the same as the result of `alert( user.ref.name )` from the previous example.
34+
Jak vidíte, výsledek `alert( vytvořUživatele().jméno )` je stejný jako výsledek `alert( uživatel.odkaz.jméno )` z předchozího příkladu.
3535

36-
Here's the opposite case:
36+
Toto je opačný příklad:
3737

3838
```js run
39-
function makeUser() {
39+
function vytvořUživatele() {
4040
return {
41-
name: "John",
41+
jméno: "Jan",
4242
*!*
43-
ref() {
43+
odkaz() {
4444
return this;
4545
}
4646
*/!*
4747
};
4848
}
4949

50-
let user = makeUser();
50+
let uživatel = vytvořUživatele();
5151

52-
alert( user.ref().name ); // John
52+
alert( ivatel.odkaz().jméno ); // Jan
5353
```
5454

55-
Now it works, because `user.ref()` is a method. And the value of `this` is set to the object before dot `.`.
55+
Teď to funguje, protože `uživatel.odkaz()` je metoda. A hodnota `this` se nastaví na objekt před tečkou `.`.

1-js/04-object-basics/04-object-methods/4-object-property-this/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ importance: 5
22

33
---
44

5-
# Using "this" in object literal
5+
# Použití „this“ v objektovém literálu
66

7-
Here the function `makeUser` returns an object.
7+
Zde funkce `vytvořUživatele` vrátí objekt.
88

9-
What is the result of accessing its `ref`? Why?
9+
Jaký je výsledek přístupu k jeho vlastnosti `odkaz`? Proč?
1010

1111
```js
12-
function makeUser() {
12+
function vytvořUživatele() {
1313
return {
14-
name: "John",
15-
ref: this
14+
jméno: "Jan",
15+
odkaz: this
1616
};
1717
}
1818

19-
let user = makeUser();
19+
let uživatel = vytvořUživatele();
2020

21-
alert( user.ref.name ); // What's the result?
21+
alert( ivatel.odkaz.jméno ); // Jaký je výsledek?
2222
```
2323

1-js/04-object-basics/04-object-methods/7-calculator/_js.view/solution.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
let calculator = {
2-
sum() {
1+
let kalkulátor = {
2+
součet() {
33
return this.a + this.b;
44
},
55

6-
mul() {
6+
součin() {
77
return this.a * this.b;
88
},
99

10-
read() {
10+
načti() {
1111
this.a = +prompt('a?', 0);
1212
this.b = +prompt('b?', 0);
1313
}

1-js/04-object-basics/04-object-methods/7-calculator/_js.view/test.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11

2-
3-
describe("calculator", function() {
2+
describe("kalkulátor", function() {
43

5-
context("when 2 and 3 entered", function() {
4+
context("když zadáme 2 a 3", function() {
65
beforeEach(function() {
76
sinon.stub(window, "prompt");
87

98
prompt.onCall(0).returns("2");
109
prompt.onCall(1).returns("3");
1110

12-
calculator.read();
11+
kalkulátor.načti();
1312
});
1413

1514
afterEach(function() {
1615
prompt.restore();
1716
});
1817

19-
it('the read get two values and saves them as object properties', function () {
20-
assert.equal(calculator.a, 2);
21-
assert.equal(calculator.b, 3);
18+
it('funkce načti načte dvě hodnoty a uloží je jako vlastnosti objektu', function () {
19+
assert.equal(kalkulátor.a, 2);
20+
assert.equal(kalkulátor.b, 3);
2221
});
2322

24-
it("the sum is 5", function() {
25-
assert.equal(calculator.sum(), 5);
23+
it("součet je 5", function() {
24+
assert.equal(kalkulátor.součet(), 5);
2625
});
2726

28-
it("the multiplication product is 6", function() {
29-
assert.equal(calculator.mul(), 6);
27+
it("součin je 6", function() {
28+
assert.equal(kalkulátor.součin(), 6);
3029
});
3130
});
3231

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22
```js run demo solution
3-
let calculator = {
4-
sum() {
3+
let kalkulátor = {
4+
součet() {
55
return this.a + this.b;
66
},
77

8-
mul() {
8+
součin() {
99
return this.a * this.b;
1010
},
1111

12-
read() {
12+
načti() {
1313
this.a = +prompt('a?', 0);
1414
this.b = +prompt('b?', 0);
1515
}
1616
};
1717

18-
calculator.read();
19-
alert( calculator.sum() );
20-
alert( calculator.mul() );
18+
kalkulátor.načti();
19+
alert( kalkulátor.součet() );
20+
alert( kalkulátor.součin() );
2121
```

1-js/04-object-basics/04-object-methods/7-calculator/task.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ importance: 5
22

33
---
44

5-
# Create a calculator
5+
# Vytvořte kalkulátor
66

7-
Create an object `calculator` with three methods:
7+
Vytvořte objekt `kalkulátor` se třemi metodami:
88

9-
- `read()` prompts for two values and saves them as object properties with names `a` and `b` respectively.
10-
- `sum()` returns the sum of saved values.
11-
- `mul()` multiplies saved values and returns the result.
9+
- `načti()` se zeptá na dvě hodnoty a uloží je jako vlastnosti objektu pod názvy po řadě `a` a `b`.
10+
- `součet()` vrátí součet uložených hodnot.
11+
- `součin()` vynásobí uložené hodnoty mezi sebou a vrátí výsledek.
1212

1313
```js
14-
let calculator = {
15-
// ... your code ...
14+
let kalkulátor = {
15+
// ... váš kód ...
1616
};
1717

18-
calculator.read();
19-
alert( calculator.sum() );
20-
alert( calculator.mul() );
18+
kalkulátor.načti();
19+
alert( kalkulátor.součet() );
20+
alert( kalkulátor.součin() );
2121
```
2222

2323
[demo]
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11

2-
let ladder = {
3-
step: 0,
4-
up: function() {
5-
this.step++;
2+
let žebřík = {
3+
stupeň: 0,
4+
nahoru: function() {
5+
this.stupeň++;
66
return this;
77
},
8-
down: function() {
9-
this.step--;
8+
dolů: function() {
9+
this.stupeň--;
1010
return this;
1111
},
12+
<<<<<<< HEAD
13+
zobrazStupeň: function() {
14+
alert(this.stupeň);
15+
=======
1216
showStep: function() {
1317
alert(this.step);
1418
return this;
19+
>>>>>>> 71da17e5960f1c76aad0d04d21f10bc65318d3f6
1520
}
1621
};
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11

2-
describe('Ladder', function() {
2+
describe('Žebřík', function() {
33
before(function() {
44
window.alert = sinon.stub(window, "alert");
55
});
66

77
beforeEach(function() {
8-
ladder.step = 0;
8+
žebřík.stupeň = 0;
99
});
1010

11-
it('up() should return this', function() {
12-
assert.equal(ladder.up(), ladder);
11+
it('nahoru() by mělo vrátit this', function() {
12+
assert.equal(žebřík.nahoru(), žebřík);
1313
});
1414

15-
it('down() should return this', function() {
16-
assert.equal(ladder.down(), ladder);
15+
it('dolů() by mělo vrátit this', function() {
16+
assert.equal(žebřík.dolů(), žebřík);
1717
});
1818

19-
it('showStep() should call alert', function() {
20-
ladder.showStep();
19+
it('zobrazStupeň() by mělo volat alert', function() {
20+
žebřík.zobrazStupeň();
2121
assert(alert.called);
2222
});
2323

24-
it('up() should increase step', function() {
25-
assert.equal(ladder.up().up().step, 2);
24+
it('nahoru() by mělo zvýšit stupeň', function() {
25+
assert.equal(žebřík.nahoru().nahoru().stupeň, 2);
2626
});
2727

28-
it('down() should decrease step', function() {
29-
assert.equal(ladder.down().step, -1);
28+
it('dolů() by mělo snížit stupeň', function() {
29+
assert.equal(žebřík.dolů().stupeň, -1);
3030
});
3131

32-
it('down().up().up().up() ', function() {
33-
assert.equal(ladder.down().up().up().up().step, 2);
32+
it('dolů().nahoru().nahoru().nahoru() ', function() {
33+
assert.equal(žebřík.dolů().nahoru().nahoru().nahoru().stupeň, 2);
3434
});
3535

3636
it('showStep() should return this', function() {
@@ -42,7 +42,7 @@ describe('Ladder', function() {
4242
});
4343

4444
after(function() {
45-
ladder.step = 0;
45+
žebřík.stupeň = 0;
4646
alert.restore();
4747
});
4848
});
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
The solution is to return the object itself from every call.
1+
Řešením je v každém volání vrátit tento objekt samotný.
22

33
```js run demo
4-
let ladder = {
5-
step: 0,
6-
up() {
7-
this.step++;
4+
let žebřík = {
5+
stupeň: 0,
6+
nahoru() {
7+
this.stupeň++;
88
*!*
99
return this;
1010
*/!*
1111
},
12-
down() {
13-
this.step--;
12+
dolů() {
13+
this.stupeň--;
1414
*!*
1515
return this;
1616
*/!*
1717
},
18-
showStep() {
19-
alert( this.step );
18+
zobrazStupeň() {
19+
alert( this.stupeň );
2020
*!*
2121
return this;
2222
*/!*
2323
}
2424
};
2525

26-
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
26+
žebřík.nahoru().nahoru().dolů().zobrazStupeň().dolů().zobrazStupeň(); // zobrazí 1, pak 0
2727
```
2828

29-
We also can write a single call per line. For long chains it's more readable:
29+
Můžeme také psát každé volání na nový řádek. U delšího zřetězení je to čitelnější:
3030

3131
```js
32-
ladder
33-
.up()
34-
.up()
35-
.down()
36-
.showStep() // 1
37-
.down()
38-
.showStep(); // 0
32+
žebřík
33+
.nahoru()
34+
.nahoru()
35+
.dolů()
36+
.zobrazStupeň() // 1
37+
.dolů()
38+
.zobrazStupeň(); // 0
3939
```

0 commit comments

Comments
 (0)