- Notifications
You must be signed in to change notification settings - Fork117
Eval: run a code string#305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 4 additions & 4 deletions1-js/99-js-misc/02-eval/1-eval-calculator/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| `eval`ı bu matematiksel ifadeyi hesaplamakta kullanalım: | ||
| ```js demo run | ||
| let expr = prompt("Aritmetik bir ifade girin", '2*3+2'); | ||
| alert( eval(expr) ); | ||
| ``` | ||
| Kullanıcı herhangi bir metin veya kod girebilir. | ||
| 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. |
6 changes: 3 additions & 3 deletions1-js/99-js-misc/02-eval/1-eval-calculator/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
69 changes: 34 additions & 35 deletions1-js/99-js-misc/02-eval/article.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,29 @@ | ||
| # Eval:kod karakter dizisi çalıştırmak | ||
| Yerleşik`eval`fonksiyonu, `kod` şeklindeki bir karakter dizisini çalıştırmayı sağlar. | ||
| Sözdizimi şu şekildedir: | ||
| ```js | ||
| let result = eval(code); | ||
| ``` | ||
| Örneğin: | ||
| ```js run | ||
| let code = 'alert("Esenlikler")'; | ||
| eval(code); //Esenlikler | ||
| ``` | ||
| Bir`eval`çalıştırmak son ifadenin sonucunu döndürür. | ||
| Örneğin: | ||
| ```js run | ||
| let value = eval('1+1'); | ||
| alert(value); // 2 | ||
| ``` | ||
| Kod, o anki sözcüksel ortamda yürütülür, bu nedenle dış değişkenlere erişebilir. | ||
| ```js run no-beautify | ||
| let a = 1; | ||
| @@ -39,69 +39,68 @@ function f() { | ||
| f(); | ||
| ``` | ||
| Aynı şekilde dış değişkenleri de değiştirebilir: | ||
| ```js untrusted refresh run | ||
| let x = 5; | ||
| eval("x = 10"); | ||
| alert(x); // 10,değer değişti | ||
| ``` | ||
| 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. | ||
| ```js untrusted refresh run | ||
| //hatırlatma: çalıştırılabilir örneklerde'use strict'varsayılan olarak etkin durumdadır. | ||
| eval("let x = 5; function f() {}"); | ||
| alert(typeof x); // undefined (böyle bir değişken yok) | ||
| //f fonksiyonu da aynı şekilde ulaşılmaz durumda | ||
| ``` | ||
| `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. | ||
| ##"Eval" kullanımı | ||
| Modern programlamada`eval`, oldukça cüzi miktarda kullanılır. Kendisinden çoğunlukla"eval is evil" (eval kötüdür) şeklinde bahsedilir. | ||
| Nedeni oldukça basit: uzun, çok uzun zaman önceJavaScript, ç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ı. | ||
| Şu an`eval` kullanmak için neredeyse hiçbir neden bulunmuyor. Eğer birisi kullanıyorsa bunumodernbri dil yapısıyla veya bir[JavaScriptModülü](info:modules) ile değiştirmek için iyi bir fırsatı var. | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. modern bir* dil | ||
| 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. | ||
| Kod küçültücüler (minifiers -JSkodları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. | ||
| `eval`ın içinde dış yerel değişkenler kullanmak kod kontrolünü zorlaştıran kötü bir programlama yöntemidir. | ||
| Eval ile bağlantılı sorunlardan kaçınmanın iki adet yolu mevcut. | ||
| **Eğer eval'laştırılmış kod dış değişkenleri kullanmıyorsas lütfen`eval`ı`window.eval(...)` şeklinde kullanın:** | ||
| Bu yöntem, koduglobalkapsamda çalıştıracaktır. | ||
| ```js untrusted refresh run | ||
| let x = 1; | ||
| { | ||
| let x = 5; | ||
| window.eval('alert(x)'); // 1 (globaldeğişken) | ||
| } | ||
| ``` | ||
| **Eğer kod yerel değişkenlere ihtiyaç duyuyorsa`new Function`ile çalıştırın ve bunları argüman olarak geçirin:** | ||
| ```js run | ||
| let f = new Function('a', 'alert(a)'); | ||
| f(5); // 5 | ||
| ``` | ||
| `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. | ||
| ##Özet | ||
| `eval(code)` yapısı karakter dizisi formatındaki bir kodu çalıştırır ve son ifadenin sonucunu döndürür. | ||
| - Olabildiğince az ihtiyaç duyularak modern JavaScript'te nadiren kullanılır. | ||
| - Global kapsamda `eval` kullanmak yerine `window.eval(code)` kullanın. | ||
| - Veya kodunuz dış kapsamdan bazı verilere ihtiyaç duyuyorsa `new Function` kullanın ve bunları argüman olarak gönderin. | ||
2 changes: 1 addition & 1 deletion1-js/99-js-misc/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| #Çeşitli |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.