-
Notifications
You must be signed in to change notification settings - Fork 114
01-proxy #354
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thelordax0
wants to merge
1
commit into
javascript-tutorial:master
Choose a base branch
from
thelordax0:thelordax0-patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
01-proxy #354
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,36 +1,36 @@ | ||
|
||
# Proxy and Reflect | ||
|
||
A *proxy* wraps another object and intercepts operations, like reading/writing properties and others, optionally handling them on its own, or transparently allowing the object to handle them. | ||
Bir *proxy* başka bir nesneyi sarar ve okuma/yazma özellikleri ve diğerleri gibi işlemleri durdurur, isteğe bağlı olarak bunları kendi başına yönetir veya şeffaf bir şekilde nesnenin bunları işlemesine izin verir. | ||
|
||
Proxies are used in many libraries and some browser frameworks. We'll see many practical applications in this chapter. | ||
Proxy'ler birçok kitaplıkta ve bazı tarayıcı çerçevelerinde kullanılır. Bu bölümde birçok pratik uygulama göreceğiz. | ||
|
||
The syntax: | ||
Söz dizimi: | ||
|
||
```js | ||
let proxy = new Proxy(target, handler) | ||
``` | ||
|
||
- `target` -- is an object to wrap, can be anything, including functions. | ||
- `handler` -- an object with "traps": methods that intercept operations., e.g. `get` for reading a property, `set` for writing a property, etc. | ||
- `target` -- sarılacak bir nesnedir, fonksiyonlar dahil herhangi bir şey olabilir. | ||
- `handler` -- 'tuzaklara' sahip bir nesne: işlemleri engelleyen yöntemler, ör. Bir özelliği okumak için 'get', bir özelliği yazmak için 'set' vb. | ||
|
||
For operations on `proxy`, if there's a corresponding trap in `handler`, then it runs, and the proxy has a chance to handle it, otherwise the operation is performed on `target`. | ||
Proxy üzerinde yapılan işlemlerde, eğer `handler` da buna karşılık gelen bir tuzak varsa çalışır ve `proxy`'nin onu ele alma şansı vardır, aksi takdirde işlem `hedef` üzerinde gerçekleştirilir. | ||
|
||
As a starting example, let's create a proxy without any traps: | ||
Başlangıç örneği olarak herhangi bir tuzak içermeyen bir proxy oluşturalım: | ||
|
||
```js run | ||
let target = {}; | ||
let proxy = new Proxy(target, {}); // empty handler | ||
let proxy = new Proxy(target, {}); // boş handler | ||
|
||
proxy.test = 5; // writing to proxy (1) | ||
alert(target.test); // 5, the property appeared in target! | ||
proxy.test = 5; // proxy'ye yazıyoruz (1) | ||
alert(target.test); // 5, the özellik hedefte göründü! | ||
|
||
alert(proxy.test); // 5, we can read it from proxy too (2) | ||
alert(proxy.test); // 5, bunu proxy'den de okuyabiliriz (2) | ||
|
||
for(let key in proxy) alert(key); // test, iteration works (3) | ||
for(let key in proxy) alert(key); // test, iterasyon çalışır (3) | ||
``` | ||
|
||
As there are no traps, all operations on `proxy` are forwarded to `target`. | ||
`proxy`'de hiç bir tuzak olmadığından `target`'e ilerlenir. | ||
|
||
1. A writing operation `proxy.test=` sets the value on `target`. | ||
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. Buraları da çevirebilir misiniz? |
||
2. A reading operation `proxy.test` returns the value from `target`. | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.