|
1 | | -# The modern mode, "use strict" |
| 1 | +# Savremeni mod, "use strict" |
2 | 2 |
|
3 | | -For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change. |
| 3 | +Dugo vremena je JavaScript evoluirao bez problema sa kompatibilnošću. Jeziku su dodate nove funkcije dok se stara funkcionalnost nije promenila. |
4 | 4 |
|
5 | | -That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript's creators got stuck in the language forever. |
| 5 | +To je imalo koristi od toga što nikada nije prekršilo postojeći kod. Ali, nedostatak je bio da se bilo kakva greška ili nesavršena odluka koju su doneli JavaScript kreatori zauvek zaglavi u jeziku. |
6 | 6 |
|
7 | | -This was the case until 2009 when ECMAScript 5 (ES5) appeared. It added new features to the language and modified some of the existing ones. To keep the old code working, most such modifications are off by default. You need to explicitly enable them with a special directive: `"use strict"`. |
| 7 | +Tako je bilo sve do 2009. godine kada se pojavio ECMAScript 5 (ES5). Jeziku je dodao nove funkcije i modifikovao neke od postojećih. Da bi stari kod radio, većina takvih modifikacija je podrazumevano isključena. Morate ih izričito omogućiti posebnom direktivom: `"use strict"`. |
8 | 8 |
|
9 | 9 | ## "use strict" |
10 | 10 |
|
11 | | -The directive looks like a string: `"use strict"` or `'use strict'`. When it is located at the top of a script, the whole script works the "modern" way. |
| 11 | +Direktiva izgleda kao string: `"use strict"` ili `'use strict'`. Kada se nalazi na vrhu skripte, ceo skript deluje na "moderan" način. |
12 | 12 |
|
13 | | -For example: |
| 13 | +Na primjer: |
14 | 14 |
|
15 | 15 | ```js |
16 | 16 | "use strict"; |
17 | 17 |
|
18 | | -// this code works the modern way |
| 18 | +// ovaj kod deluje na savremen način |
19 | 19 | ... |
20 | 20 | ``` |
21 | 21 |
|
22 | | -We will learn functions (a way to group commands) soon. Looking ahead, let's note that `"use strict"` can be put at the beginning of the function body instead of the whole script. Doing that enables strict mode in that function only. But usually, people use it for the whole script. |
| 22 | +Uskoro ćemo naučiti funkcije (način za grupisanje komandi). Gledajući napred, uzmimo to u obzir `"use strict"` može se staviti na početak tela funkcije umesto celog skripta. To omogućava strogi režim samo u toj funkciji. Ali obično ga ljudi koriste za cijelu skriptu. |
23 | 23 |
|
24 | 24 |
|
25 | | -````warn header="Ensure that \"use strict\" is at the top" |
26 | | -Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled. |
| 25 | +````warn header="Obezbijedi da je \"use strict\" na vrhu" |
| 26 | +Obavezno proverite da li se „use strict“ nalazi na vrhu vaše skripte, jer u suprotnom strogi režim možda neće biti omogućen. |
27 | 27 |
|
28 | | -Strict mode isn't enabled here: |
| 28 | +
|
| 29 | +Strogi režim ovde nije omogućen: |
29 | 30 |
|
30 | 31 | ```js no-strict |
31 | | -alert("some code"); |
32 | | -// "use strict" below is ignored--it must be at the top |
| 32 | +alert("neki kod"); |
| 33 | +// "use strict" ispod se ignoriše-- mora biti na vrhu |
33 | 34 |
|
34 | 35 | "use strict"; |
35 | 36 |
|
36 | | -// strict mode is not activated |
| 37 | +// strogi režim nije omogućen |
37 | 38 | ``` |
38 | 39 |
|
39 | | -Only comments may appear above `"use strict"`. |
| 40 | +Gore se mogu pojaviti samo komentari `"use strict"`. |
40 | 41 | ```` |
41 | 42 |
|
42 | | -```warn header="There's no way to cancel `use strict`" |
43 | | -There is no directive like `"no use strict"` that reverts the engine to old behavior. |
| 43 | +```warn header="Nema načina da otkažete `use strict`" |
| 44 | +Ne postoji takva direktiva `"no use strict"` koja vraća motor na staro ponašanje. |
44 | 45 |
|
45 | | -Once we enter strict mode, there's no return. |
| 46 | +Jednom kada uđemo u strogi režim, nema povratka. |
46 | 47 | ``` |
47 | 48 |
|
48 | | -## Browser console |
| 49 | +## Konzola pregledača |
49 | 50 |
|
50 | | -For the future, when you use a browser console to test features, please note that it doesn't `use strict` by default. |
| 51 | +Kada za testiranje funkcija koristite konzolu pregledača za ubuduće, imajte na umu da to nema `use strict` podrazumijevano. |
51 | 52 |
|
52 | | -Sometimes, when `use strict` makes a difference, you'll get incorrect results. |
| 53 | +Ponekad, kada `use strict` čini razliku, dobićete pogrešne rezultate. |
53 | 54 |
|
54 | | -You can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this: |
| 55 | +Možete da pokušate da pritisnete `taster:Shift+Enter` da unesete više redova i stavite „use strict“ na vrh, ovako: |
55 | 56 |
|
56 | 57 | ```js |
57 | | -'use strict'; <Shift+Enter for a newline> |
58 | | -// ...your code |
59 | | -<Enter to run> |
| 58 | +'use strict'; <Shift+Enter za novi red> |
| 59 | +// ...tvoj kod |
| 60 | +<Enter za pokretanje> |
60 | 61 | ``` |
61 | 62 |
|
62 | | -It works in most browsers, namely Firefox and Chrome. |
| 63 | +Radi u većini pregledača, naime Firefox i Chrome. |
63 | 64 |
|
64 | | -If it doesn't, the most reliable way to ensure `use strict` would be to input the code into console like this: |
| 65 | +Ako ne, najpouzdaniji način da to osigurate `use strict` bilo bi da unesete kod u konzolu ovako: |
65 | 66 |
|
66 | 67 | ```js |
67 | 68 | (function() { |
68 | 69 | 'use strict'; |
69 | 70 |
|
70 | | - // ...your code... |
| 71 | + // ...tvoj kod... |
71 | 72 | })() |
72 | 73 | ``` |
73 | 74 |
|
74 | | -## Always "use strict" |
| 75 | +## Uvjek "use strict" |
75 | 76 |
|
76 | | -We have yet to cover the differences between strict mode and the "default" mode. |
| 77 | +Moramo još da pokrijemo razlike između strogog načina rada i "uobičajenog" režima. |
77 | 78 |
|
78 | | -In the next chapters, as we learn language features, we'll note the differences between the strict and default modes. Luckily, there aren't many and they actually make our lives better. |
| 79 | +U sledećim poglavljima, dok učimo jezičke karakteristike, primetićemo razlike između strogog i zadanog načina rada. Srećom, nema ih mnogo i oni nam zapravo poboljšavaju život. |
79 | 80 |
|
80 | | -For now, it's enough to know about it in general: |
| 81 | +Za sada je dovoljno znati o tome uopšte: |
81 | 82 |
|
82 | | -1. The `"use strict"` directive switches the engine to the "modern" mode, changing the behavior of some built-in features. We'll see the details later in the tutorial. |
83 | | -2. Strict mode is enabled by placing `"use strict"` at the top of a script or function. Several language features, like "classes" and "modules", enable strict mode automatically. |
84 | | -3. Strict mode is supported by all modern browsers. |
85 | | -4. We recommended always starting scripts with `"use strict"`. All examples in this tutorial assume strict mode unless (very rarely) specified otherwise. |
| 83 | +1. `"use strict"` direktiva prebacuje motor u „moderan“ mod, menjajući ponašanje nekih ugrađenih funkcija. Detalje ćemo videti kasnije u vodiču. |
| 84 | +2. trogi režim je omogućen postavljanjem `"use strict"` na vrhu skripte ili funkcije. Nekoliko jezičnih funkcija, poput „klase“ i „modula“, automatski omogućuju strogi režim. |
| 85 | +3. Strogi režim podržavaju svi moderni pregledači. |
| 86 | +4. Preporučujemo uvek pokretanje skripti sa `"use strict"`. Svi primjeri u ovom vodiču pretpostavljaju strogi način rada, osim ako (vrlo rijetko) nije drugačije određeno. |
0 commit comments