aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/javascript/reference/global_objects/proxy
diff options
context:
space:
mode:
authort7yang <t7yang@gmail.com>2022-01-10 08:38:05 +0800
committerIrvin <irvinfly@gmail.com>2022-02-16 02:35:54 +0800
commit6ca84f1794af830ada9736d7289ce29aabb04ca3 (patch)
treebb8000558a4eb75d7be1f3543d66bfc4c44bada9 /files/zh-tw/web/javascript/reference/global_objects/proxy
parent8d1313c84cc82d81363ed62b75baedb9a65ff2e3 (diff)
downloadtranslated-content-6ca84f1794af830ada9736d7289ce29aabb04ca3.tar.gz
translated-content-6ca84f1794af830ada9736d7289ce29aabb04ca3.tar.bz2
translated-content-6ca84f1794af830ada9736d7289ce29aabb04ca3.zip
remove `notranslate` class in zh-TW
Diffstat (limited to 'files/zh-tw/web/javascript/reference/global_objects/proxy')
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/proxy/index.html18
1 files changed, 9 insertions, 9 deletions
diff --git a/files/zh-tw/web/javascript/reference/global_objects/proxy/index.html b/files/zh-tw/web/javascript/reference/global_objects/proxy/index.html
index 54a71be888..f41b0a6caa 100644
--- a/files/zh-tw/web/javascript/reference/global_objects/proxy/index.html
+++ b/files/zh-tw/web/javascript/reference/global_objects/proxy/index.html
@@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Proxy
<h2 id="語法">語法</h2>
-<pre class="syntaxbox notranslate">var p = new Proxy(target, handler);
+<pre class="syntaxbox">var p = new Proxy(target, handler);
</pre>
<h3 id="參數">參數</h3>
@@ -58,7 +58,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Proxy
<p>In this simple example the number <code>37</code> gets returned as the default value when the property name is not in the object. It is using the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/get"><code>get</code></a> handler.</p>
-<pre class="brush: js notranslate">var handler = {
+<pre class="brush: js">var handler = {
get: function(target, name) {
return name in target ?
target[name] :
@@ -78,7 +78,7 @@ console.log('c' in p, p.c); // false, 37
<p>In this example, we are using a native JavaScript object to which our proxy will forward all operations that are applied to it.</p>
-<pre class="brush: js notranslate">var target = {};
+<pre class="brush: js">var target = {};
var p = new Proxy(target, {});
p.a = 37; // operation forwarded to the target
@@ -90,7 +90,7 @@ console.log(target.a); // 37. The operation has been properly forwarded
<p>With a <code>Proxy</code>, you can easily validate the passed value for an object. This example uses the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/set"><code>set</code></a> handler.</p>
-<pre class="brush: js notranslate">let validator = {
+<pre class="brush: js">let validator = {
set: function(obj, prop, value) {
if (prop === 'age') {
if (!Number.isInteger(value)) {
@@ -120,7 +120,7 @@ person.age = 300; // Throws an exception</pre>
<p>A function proxy could easily extend a constructor with a new constructor. This example uses the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/construct"><code>construct</code></a> and <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/apply"><code>apply</code></a> handlers.</p>
-<pre class="brush: js notranslate">function extend(sup, base) {
+<pre class="brush: js">function extend(sup, base) {
var descriptor = Object.getOwnPropertyDescriptor(
base.prototype, 'constructor'
);
@@ -161,7 +161,7 @@ console.log(Peter.age); // 13</pre>
<p>Sometimes you want to toggle the attribute or class name of two different elements. Here's how using the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/set"><code>set</code></a> handler.</p>
-<pre class="brush: js notranslate">let view = new Proxy({
+<pre class="brush: js">let view = new Proxy({
selected: null
},
{
@@ -196,7 +196,7 @@ console.log(i2.getAttribute('aria-selected')); // 'true'</pre>
<p>The <code>products</code> proxy object evaluates the passed value and convert it to an array if needed. The object also supports an extra property called <code>latestBrowser</code> both as a getter and a setter.</p>
-<pre class="brush: js notranslate">let products = new Proxy({
+<pre class="brush: js">let products = new Proxy({
browsers: ['Internet Explorer', 'Netscape']
},
{
@@ -241,7 +241,7 @@ console.log(products.latestBrowser); // 'Chrome'</pre>
<p>This proxy extends an array with some utility features. As you see, you can flexibly "define" properties without using <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties"><code>Object.defineProperties</code></a>. This example can be adapted to find a table row by its cell. In that case, the target will be <a href="/en-US/docs/DOM/table.rows"><code>table.rows</code></a>.</p>
-<pre class="brush: js notranslate">let products = new Proxy([
+<pre class="brush: js">let products = new Proxy([
{ name: 'Firefox', type: 'browser' },
{ name: 'SeaMonkey', type: 'browser' },
{ name: 'Thunderbird', type: 'mailer' }
@@ -302,7 +302,7 @@ console.log(products.number); // 3
<p>Now in order to create a complete sample <code>traps</code> list, for didactic purposes, we will try to proxify a <em>non native</em> object that is particularly suited to this type of operation: the <code>docCookies</code> global object created by <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie/Simple_document.cookie_framework" title="https://developer.mozilla.org/en-US/docs/DOM/document.cookie#A_little_framework.3A_a_complete_cookies_reader.2Fwriter_with_full_unicode_support">the "little framework" published on the <code>document.cookie</code> page</a>.</p>
-<pre class="brush: js notranslate">/*
+<pre class="brush: js">/*
var docCookies = ... get the "docCookies" object here:
https://developer.mozilla.org/en-US/docs/DOM/document.cookie#A_little_framework.3A_a_complete_cookies_reader.2Fwriter_with_full_unicode_support
*/