Skip to content

Commit fc36130

Browse files
authored
1/3
1 parent 0b7cdf7 commit fc36130

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Object methods, "this"
1+
# Metody obiektów, "this"
22

3-
Objects are usually created to represent entities of the real world, like users, orders and so on:
3+
Obiekty zazwyczaj są tworzone po to, żeby przedstawiać rzeczywiste podmioty, takie jak użytkownicy, zadania do wykonania i tym podobne:
44

55
```js
66
let user = {
@@ -9,13 +9,13 @@ let user = {
99
};
1010
```
1111

12-
And, in the real world, a user can *act*: select something from the shopping cart, login, logout etc.
12+
I tak jak w rzeczywistości, użytkownik może *działać*: wybrać coś z koszyka, zalogować się, wylogować itd.
1313

14-
Actions are represented in JavaScript by functions in properties.
14+
Czynności są w JavaScript'cie funkcjami we właściwościach obiektu.
1515

16-
## Method examples
16+
## Przykłady metod
1717

18-
For a start, let's teach the `user` to say hello:
18+
Na początek, nauczmy użytkownika `user` jak się przywitać:
1919

2020
```js run
2121
let user = {
@@ -25,74 +25,75 @@ let user = {
2525

2626
*!*
2727
user.sayHi = function() {
28-
alert("Hello!");
28+
alert("Cześć!");
2929
};
3030
*/!*
3131

32-
user.sayHi(); // Hello!
32+
user.sayHi(); // Cześć!
3333
```
3434

35-
Here we've just used a Function Expression to create the function and assign it to the property `user.sayHi` of the object.
35+
Właśnie użyliśmy Wyrażenia Funkcji do stworzenia funkcji i przypisaliśmy ją do właściwości `user.sayHi` obiektu.
3636

37-
Then we can call it. The user can now speak!
37+
Następnie ją wywołaliśmy. Użytkownik potrafi teraz mówić!
3838

39-
A function that is the property of an object is called its *method*.
39+
Funkcja która jest właściwością obiektu nazywamy *metodą*.
4040

41-
So, here we've got a method `sayHi` of the object `user`.
41+
Także mamy tutaj metodę `sayHi` obiektu `user`.
4242

43-
Of course, we could use a pre-declared function as a method, like this:
43+
Oczywiście moglibyśmy również posłużyć się wcześniej zadeklarowaną funkcją jako metodą:
4444

4545
```js run
4646
let user = {
4747
// ...
4848
};
4949

5050
*!*
51-
// first, declare
51+
// najpierw deklarujemy
5252
function sayHi() {
53-
alert("Hello!");
53+
alert("Cześć!");
5454
};
5555

56-
// then add as a method
56+
// następnie dodajemy jako metodę
5757
user.sayHi = sayHi;
5858
*/!*
5959

60-
user.sayHi(); // Hello!
60+
user.sayHi(); // Cześć!
6161
```
6262

6363
```smart header="Object-oriented programming"
64-
When we write our code using objects to represent entities, that's called [object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming), in short: "OOP".
64+
Kiedy piszemy kod wykorzystujący obiekty do reprezentowania podmiotów, nazywamy to[programowaniem obiektowym](https://pl.wikipedia.org/wiki/Programowanie_obiektowe), w skrócie:
65+
"OOP".
6566
66-
OOP is a big thing, an interesting science of its own. How to choose the right entities? How to organize the interaction between them? That's architecture, and there are great books on that topic, like "Design Patterns: Elements of Reusable Object-Oriented Software" by E.Gamma, R.Helm, R.Johnson, J.Vissides or "Object-Oriented Analysis and Design with Applications" by G.Booch, and more.
67+
OOP to bardzo rozległy i interesujący temat. Jak wybrać właściwe podmioty? Jak stworzyć zależności między nimi? Jest to cała architektura i istnieje wiele świetnych książek traktujących ten temat, jak np. "Wzorce projektowe. Elementy oprogramowania" autorstwa E.Gamma, R.Helm, R.Johnson, J.Vissides, lub "Object-Oriented Analysis and Design with Applications" G.Booch, i wiele innych
6768
```
68-
### Method shorthand
69+
### Skróty dla metod
6970

70-
There exists a shorter syntax for methods in an object literal:
71+
Istnieje skrócona składnia dla metod w literałach obiektowych:
7172

7273
```js
73-
// these objects do the same
74+
// te obiekty działają tak samo
7475

7576
user = {
7677
sayHi: function() {
77-
alert("Hello");
78+
alert("Cześć");
7879
}
7980
};
8081

81-
// method shorthand looks better, right?
82+
// skrócona składnia wygląda lepiej, prawda ?
8283
user = {
8384
*!*
84-
sayHi() { // same as "sayHi: function()"
85+
sayHi() { // to samo co "sayHi: function()"
8586
*/!*
86-
alert("Hello");
87+
alert("Cześć");
8788
}
8889
};
8990
```
9091

91-
As demonstrated, we can omit `"function"` and just write `sayHi()`.
92+
Jak wyżej, możemy pominąć `"function"` i po prostu użyć `sayHi()`.
9293

93-
To tell the truth, the notations are not fully identical. There are subtle differences related to object inheritance (to be covered later), but for now they do not matter. In almost all cases the shorter syntax is preferred.
94+
Szczerze mowiąc, oba zapisy nie są całkowicie identyczne. Istnieją subtelne różnice między nimi, związane z dziedziczeniem (ten temat poruszymy później), ale na tem moment nie ma to znaczenia. W prawie każdym przypadku lepiej użyć skróconej wersji.
9495

95-
## "this" in methods
96+
## "this" w metodach
9697

9798
It's common that an object method needs to access the information stored in the object to do its job.
9899

0 commit comments

Comments
 (0)