Skip to content

Commit 6e0e50a

Browse files
yinkarHuseyin
authored andcommitted
Eval: run a code string translation
1 parent 113a390 commit 6e0e50a

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Let's use `eval` to calculate the maths expression:
1+
`eval`ı bu matematiksel ifadeyi hesaplamakta kullanalım:
22

33
```js demo run
4-
let expr = prompt("Type an arithmetic expression?", '2*3+2');
4+
let expr = prompt("Aritmetik bir ifade girin", '2*3+2');
55

66
alert( eval(expr) );
77
```
88

9-
The user can input any text or code though.
9+
Kullanıcı herhangi bir metin veya kod girebilir.
1010

11-
To make things safe, and limit it to arithmetics only, we can check the `expr` using a [regular expression](info:regular-expressions), so that it only may contain digits and operators.
11+
Bunları güvenli hale getirip yalnızca aritmetiksel ifadelerle sınıflandırabilmek için `expr` değişkenini [düzenli ifadeler](info:regular-expressions) kullanarak kontrol edebiliriz, böylece ifade yalnızca rakam ve operatör içerebilecektir.

1-js/99-js-misc/02-eval/1-eval-calculator/task.md

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

33
---
44

5-
# Eval-calculator
5+
# Eval-hesaplayıcı
66

7-
Create a calculator that prompts for an arithmetic expression and returns its result.
7+
Aritmetik bir ifade isteyen ve sonucunu döndüren bir hesap makinesi olutşurun.
88

9-
There's no need to check the expression for correctness in this task.
9+
Bu görevde ifadenin doğruluğunu kontrol etmenize gerek yok.
1010

1111
[demo]

1-js/99-js-misc/02-eval/article.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Eval: run a code string
1+
# Eval: kod karakter dizisi çalıştırmak
22

3-
The built-in `eval` function allows to execute a string of `code`.;
3+
Yerleşik `eval` fonksiyonu, `kod` şeklindeki bir karakter dizisini çalıştırmayı sağlar.
44

5-
The syntax is:
5+
Sözdizimi şu şekildedir:
66

77
```js
88
let result = eval(code);
99
```
1010

11-
For example:
11+
Örneğin:
1212

1313
```js run
14-
let code = 'alert("Hello")';
15-
eval(code); // Hello
14+
let code = 'alert("Esenlikler")';
15+
eval(code); // Esenlikler
1616
```
1717

18-
A call to `eval` returns the result of the last statement.
18+
Bir `eval` çalıştırmak son ifadenin sonucunu döndürür.
1919

20-
For example:
20+
Örneğin:
2121
```js run
2222
let value = eval('1+1');
2323
alert(value); // 2
2424
```
2525

26-
The code is executed in the current lexical environment, so it can see outer variables:
26+
Kod, o anki sözcüksel ortamda yürütülür, bu nedenle dış değişkenlere erişebilir.
2727

2828
```js run no-beautify
2929
let a = 1;
@@ -39,69 +39,68 @@ function f() {
3939
f();
4040
```
4141

42-
It can change outer variables as well:
42+
Aynı şekilde dış değişkenleri de değiştirebilir:
4343

4444
```js untrusted refresh run
4545
let x = 5;
4646
eval("x = 10");
47-
alert(x); // 10, value modified
47+
alert(x); // 10, değer değişti
4848
```
4949

50-
In strict mode, `eval` has its own lexical environment. So functions and variables, declared inside eval, are not visible outside:
50+
Katı modda `eval` kendi sözcüksel ortamına sahiptir. Bu nedenle eval içerisinde tanımlanan fonksiyon ve değişkenler dışarıdan ulaşılabilir değildir.
5151

5252
```js untrusted refresh run
53-
// reminder: 'use strict' is enabled in runnable examples by default
53+
// hatırlatma: çalıştırılabilir örneklerde 'use strict' varsayılan olarak etkin durumdadır.
5454

5555
eval("let x = 5; function f() {}");
5656

57-
alert(typeof x); // undefined (no such variable)
58-
// function f is also not visible
57+
alert(typeof x); // undefined (böyle bir değişken yok)
58+
// f fonksiyonu da aynı şekilde ulaşılmaz durumda
5959
```
6060

61-
Without `use strict`, `eval` doesn't have its own lexical environment, so we would see `x` and `f` outside.
61+
`use strict` kullanılmadığı takdirde `eval`, kendi sözcüksel ortamına sahip değildir, bu yüzden `x` ve `f` ifadelerini dışarıdan görebiliriz.
6262

63-
## Using "eval"
63+
## "Eval" kullanımı
6464

65-
In modern programming `eval` is used very sparingly. It's often said that "eval is evil".
65+
Modern programlamada `eval`, oldukça cüzi miktarda kullanılır. Kendisinden çoğunlukla "eval is evil" (eval kötüdür) şeklinde bahsedilir.
6666

67-
The reason is simple: long, long time ago JavaScript was a much weaker language, many things could only be done with `eval`. But that time passed a decade ago.
67+
Nedeni oldukça basit: uzun, çok uzun zaman önce JavaScript, çoğu şeyin yalnızca `eval` ile yapılabildiği, oldukça zayıf bir dildi. Fakat bu artık on yıl kadar öncede kaldı.
6868

69-
Right now, there's almost no reason to use `eval`. If someone is using it, there's a good chance they can replace it with a modern language construct or a [JavaScript Module](info:modules).
69+
Şu an `eval` kullanmak için neredeyse hiçbir neden bulunmuyor. Eğer birisi kullanıyorsa bunu modern bri dil yapısıyla veya bir [JavaScript Modülü](info:modules) ile değiştirmek için iyi bir fırsatı var.
7070

71-
Still, if you're sure you need to dynamically `eval` a string of code, please note that its ability to access outer variables has side-effects.
71+
Halen dinamik bir `eval` karakter dizisi şeklinde bir koda ihtiyacınız varsa lütfen bunun dış değişkenlere yan etkilere neden olarak erişebileceğinin farkında olun.
7272

73-
Code minifiers (tools used before JS gets to production, to compress it) replace local variables with shorter ones for brewity. That's usually safe, but not if `eval` is used, as it may reference them. So minifiers don't replace all local variables that might be visible from `eval`. That negatively affects code compression ratio.
73+
Kod küçültücüler (minifiers - JS kodlarını yayınlamadan önce sıkıştıran araçlar) yerel değişkenleri üretim için kısa olanlarıyla değiştirir. Bu genellikle güvenlidir, şayet birçok referansa sahip `eval` kullanılmıyorsa. Dolayısıyla küçültücüler `eval`dan görülebilen tüm yerel değişkenleri değiştirmez. Bu, kod sıkıştırma oranını büyük oranda kötü etkileyecektir.
7474

75-
Using outer local variables inside `eval` is a bad programming practice, as it makes maintaining the code more difficult.
75+
`eval`ın içinde dış yerel değişkenler kullanmak kod kontrolünü zorlaştıran kötü bir programlama yöntemidir.
7676

77-
There are two ways how to evade any eval-related problems.
77+
Eval ile bağlantılı sorunlardan kaçınmanın iki adet yolu mevcut.
7878

79-
**If eval'ed code doesn't use outer variables, please call `eval` as `window.eval(...)`:**
79+
**Eğer eval'laştırılmış kod dış değişkenleri kullanmıyorsas lütfen `eval`ı `window.eval(...)` şeklinde kullanın:**
8080

81-
This way the code is executed in the global scope:
81+
Bu yöntem, kodu global kapsamda çalıştıracaktır.
8282

8383
```js untrusted refresh run
8484
let x = 1;
8585
{
8686
let x = 5;
87-
window.eval('alert(x)'); // 1 (global variable)
87+
window.eval('alert(x)'); // 1 (global değişken)
8888
}
8989
```
9090

91-
**If your code needs local variables, execute it with `new Function` and pass them as arguments:**
91+
**Eğer kod yerel değişkenlere ihtiyaç duyuyorsa `new Function` ile çalıştırın ve bunları argüman olarak geçirin:**
9292

9393
```js run
9494
let f = new Function('a', 'alert(a)');
9595

9696
f(5); // 5
9797
```
9898

99-
The `new Function` construct is explained in the chapter <info:new-function>. It creates a function from a string, also in the global scope. So it can't see local variables. But it's so much clearer to pass them explicitly as arguments, like in the example above.
99+
`new Function` yapısı <info:new-function> bölümünde açıklanmıştır. Bu, bir karakter dizisinden, aynı zamanda global kapsamda olan bir fonksiyon yaratır. Bu yüzden yerel değişkenleri göremez. Fakat yukarıdaki örnekte de görülebileceği üzere bunları açık şekilde argüman olarak göndermek çok daha temiz bir yoldur.
100100

101-
## Summary
101+
## Özet
102102

103-
A call to `eval(code)` runs the string of code and returns the result of the last statement.
104-
- Rarely used in modern JavaScript, as there's usually no need.
105-
- Can access outer local variables. That's considered bad practice.
106-
- Instead, to `eval` the code in the global scope, use `window.eval(code)`.
107-
- Or, if your code needs some data from the outer scope, use `new Function` and pass it as arguments.
103+
`eval(code)` yapısı karakter dizisi formatındaki bir kodu çalıştırır ve son ifadenin sonucunu döndürür.
104+
- Olabildiğince az ihtiyaç duyularak modern JavaScript'te nadiren kullanılır.
105+
- Global kapsamda `eval` kullanmak yerine `window.eval(code)` kullanın.
106+
- Veya kodunuz dış kapsamdan bazı verilere ihtiyaç duyuyorsa `new Function` kullanın ve bunları argüman olarak gönderin.

1-js/99-js-misc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
# Miscellaneous
2+
# Çeşitli

0 commit comments

Comments
 (0)