diff options
author | t7yang <t7yang@gmail.com> | 2022-01-10 08:38:05 +0800 |
---|---|---|
committer | Irvin <irvinfly@gmail.com> | 2022-02-16 02:35:54 +0800 |
commit | 6ca84f1794af830ada9736d7289ce29aabb04ca3 (patch) | |
tree | bb8000558a4eb75d7be1f3543d66bfc4c44bada9 /files/zh-tw/web/javascript/reference/global_objects | |
parent | 8d1313c84cc82d81363ed62b75baedb9a65ff2e3 (diff) | |
download | translated-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')
10 files changed, 56 insertions, 56 deletions
diff --git a/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html b/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html index 453564d528..1b6497b07a 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/array/length/index.html @@ -7,7 +7,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/length <p><code><strong>length</strong></code> 為<code>Array物件的屬性</code> ,可供設定或回傳該陣列實體中包含的元素個數。其值必為一大於零、32位元、且恆大於該陣列最大索引數的正整數。</p> -<pre class="brush: js notranslate">var items = ['shoes', 'shirts', 'socks', 'sweaters']; +<pre class="brush: js">var items = ['shoes', 'shirts', 'socks', 'sweaters']; items.length; // returns 4</pre> @@ -16,7 +16,7 @@ items.length; <p><code>length</code> 屬性的值必為一正整數,其值必介於 0 ~ 2<sup>32</sup> (不包含)之間.</p> -<pre class="brush: js notranslate">var namelistA = new Array(4294967296); //2<sup>32</sup><sup> = </sup>4294967296 +<pre class="brush: js">var namelistA = new Array(4294967296); //2<sup>32</sup><sup> = </sup>4294967296 var namelistC = new Array(-100) //負數 console.log(namelistA.length); //RangeError: Invalid array length @@ -32,7 +32,7 @@ console.log(namelistB.length); <p>你可以透過改變 <code>length</code> 屬性來改變陣列的長度。當你透過 <code>length</code> 屬性來增加陣列的長度時,陣列中實際的元素也會隨之增加。舉例來說,當你將 array.length 由 2 增加為3,則改動後該陣列即擁有3個元素,該新增的元素則會是一個不可迭代(non-iterable)的空槽(empty slot)。</p> -<pre class="notranslate">const arr = [1, 2]; +<pre>const arr = [1, 2]; console.log(arr); // [ 1, 2 ] @@ -62,7 +62,7 @@ arr.forEach(element => console.log(element)); // 空元素無法被迭代 <p>以下範例中, 陣列 <code>numbers</code> 透過 <code>length</code> 屬性進行迭代操作,並將其內容值加倍。</p> -<pre class="brush: js notranslate">var numbers = [1, 2, 3, 4, 5]; +<pre class="brush: js">var numbers = [1, 2, 3, 4, 5]; var length = numbers.length; for (var i = 0; i < length; i++) { numbers[i] *= 2; @@ -74,7 +74,7 @@ for (var i = 0; i < length; i++) { <p>以下範例中, 陣列 <code>numbers</code> 的長度若大於 3,則將其長度縮減至 3。</p> -<pre class="brush: js notranslate">var numbers = [1, 2, 3, 4, 5]; +<pre class="brush: js">var numbers = [1, 2, 3, 4, 5]; if (numbers.length > 3) { numbers.length = 3; diff --git a/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html b/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html index e9cb1fb02c..7079acee9d 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/slice <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate"><var>arr</var>.slice(<em>[</em><var>begin[</var>, <var>end]]</var>) +<pre class="syntaxbox"><var>arr</var>.slice(<em>[</em><var>begin[</var>, <var>end]]</var>) </pre> <h3 id="參數">參數</h3> @@ -56,7 +56,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/slice <h3 id="Return_a_portion_of_an_existing_array">Return a portion of an existing array</h3> -<pre class="brush: js notranslate">var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']; +<pre class="brush: js">var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']; var citrus = fruits.slice(1, 3); // fruits contains ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango'] @@ -67,7 +67,7 @@ var citrus = fruits.slice(1, 3); <p>In the following example, <code>slice</code> creates a new array, <code>newCar</code>, from <code>myCar</code>. Both include a reference to the object <code>myHonda</code>. When the color of <code>myHonda</code> is changed to purple, both arrays reflect the change.</p> -<pre class="brush: js notranslate">// Using slice, create newCar from myCar. +<pre class="brush: js">// Using slice, create newCar from myCar. var myHonda = { color: 'red', wheels: 4, engine: { cylinders: 4, size: 2.2 } }; var myCar = [myHonda, 2, 'cherry condition', 'purchased 1997']; var newCar = myCar.slice(0, 2); @@ -90,7 +90,7 @@ console.log('newCar[0].color = ' + newCar[0].color); <p>This script writes:</p> -<pre class="brush: js notranslate">myCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2, +<pre class="brush: js">myCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2, 'cherry condition', 'purchased 1997'] newCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2] myCar[0].color = red @@ -104,7 +104,7 @@ newCar[0].color = purple <p><code>slice</code> method can also be called to convert Array-like objects / collections to a new Array. You just bind the method to the object. The {{jsxref("Functions/arguments", "arguments")}} inside a function is an example of an 'array-like object'.</p> -<pre class="brush: js notranslate">function list() { +<pre class="brush: js">function list() { return Array.prototype.slice.call(arguments); } @@ -113,7 +113,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3] <p>Binding can be done with the .<code>call</code> function of {{jsxref("Function.prototype")}} and it can also be reduced using <code>[].slice.call(arguments)</code> instead of <code>Array.prototype.slice.call</code>. Anyway, it can be simplified using {{jsxref("Function.prototype.bind", "bind")}}.</p> -<pre class="brush: js notranslate">var unboundSlice = Array.prototype.slice; +<pre class="brush: js">var unboundSlice = Array.prototype.slice; var slice = Function.prototype.call.bind(unboundSlice); function list() { @@ -127,7 +127,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3] <p>Although host objects (such as DOM objects) are not required by spec to follow the Mozilla behavior when converted by <code>Array.prototype.slice</code> and IE < 9 does not do so, versions of IE starting with version 9 do allow this. “Shimming” it can allow reliable cross-browser behavior. As long as other modern browsers continue to support this ability, as currently do IE, Mozilla, Chrome, Safari, and Opera, developers reading (DOM-supporting) slice code relying on this shim will not be misled by the semantics; they can safely rely on the semantics to provide the now apparently <em>de facto</em> standard behavior. (The shim also fixes IE to work with the second argument of <code>slice()</code> being an explicit {{jsxref("null")}}/{{jsxref("undefined")}} value as earlier versions of IE also did not allow but all modern browsers, including IE >= 9, now do.)</p> -<pre class="brush: js notranslate">/** +<pre class="brush: js">/** * Shim for "fixing" IE's lack of support (IE < 9) for applying slice * on host objects like NamedNodeMap, NodeList, and HTMLCollection * (technically, since host objects have been implementation-dependent, diff --git a/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html b/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html index fb55827283..18d250f6fd 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/date/getday/index.html @@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate"><code><var>dateObj</var>.getDay()</code></pre> +<pre class="syntaxbox"><code><var>dateObj</var>.getDay()</code></pre> <h3 id="返回值">返回值</h3> @@ -25,7 +25,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay <p>下面第二行表示根據日期對象'Xmas95'的值,把1賦值給'weekday'。則1995年12月25日是星期一。</p> -<pre class="brush: js notranslate">var Xmas95 = new Date('December 25, 1995 23:15:30'); +<pre class="brush: js">var Xmas95 = new Date('December 25, 1995 23:15:30'); var weekday = Xmas95.getDay(); console.log(weekday); // 1 @@ -34,7 +34,7 @@ console.log(weekday); // 1 <div class="blockIndicator note"> <p><strong>Note:</strong> 如果需要,可以使用{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}加上<code>options</code>參數來獲取星期幾全名。使使用此方法能輕鬆做出各種國際語言:</p> -<pre class="brush: js notranslate">var options = { weekday: 'long'}; +<pre class="brush: js">var options = { weekday: 'long'}; console.log(new Intl.DateTimeFormat('en-US', options).format(Xmas95)); // Monday console.log(new Intl.DateTimeFormat('de-DE', options).format(Xmas95)); diff --git a/files/zh-tw/web/javascript/reference/global_objects/math/pow/index.html b/files/zh-tw/web/javascript/reference/global_objects/math/pow/index.html index 2bf7ffdc68..7119ba5862 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/math/pow/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/math/pow/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/pow <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate"><code>Math.pow(<var>base</var>, <var>exponent</var>)</code></pre> +<pre class="syntaxbox"><code>Math.pow(<var>base</var>, <var>exponent</var>)</code></pre> <h3 id="參數">參數</h3> @@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/pow <h3 id="使用_Math.pow">使用 <code>Math.pow()</code></h3> -<pre class="brush: js notranslate">// simple +<pre class="brush: js">// simple Math.pow(7, 2); // 49 Math.pow(7, 3); // 343 Math.pow(2, 10); // 1024 diff --git a/files/zh-tw/web/javascript/reference/global_objects/math/random/index.html b/files/zh-tw/web/javascript/reference/global_objects/math/random/index.html index 1613c18777..896d4ab948 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/math/random/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/math/random/index.html @@ -18,7 +18,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate">Math.random()</pre> +<pre class="syntaxbox">Math.random()</pre> <h3 id="回傳值_Return_value">回傳值 Return value</h3> @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <h3 id="Getting_a_random_number_between_0_inclusive_and_1_exclusive">Getting a random number between 0 (inclusive) and 1 (exclusive)</h3> -<pre class="brush: js notranslate">function getRandom() { +<pre class="brush: js">function getRandom() { return Math.random(); } </pre> @@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>This example returns a random number between the specified values. The returned value is no lower than (and may possibly equal) <code>min</code>, and is less than (and not equal) <code>max</code>.</p> -<pre class="brush: js notranslate">function getRandomArbitrary(min, max) { +<pre class="brush: js">function getRandomArbitrary(min, max) { return Math.random() * (max - min) + min; } </pre> @@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>This example returns a random <em>integer</em> between the specified values. The value is no lower than <code>min</code> (or the next integer greater than <code>min</code> if <code>min</code> isn't an integer), and is less than (but not equal to) <code>max</code>.</p> -<pre class="brush: js notranslate">function getRandomInt(min, max) { +<pre class="brush: js">function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive @@ -63,7 +63,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random <p>While the <code>getRandomInt()</code> function above is inclusive at the minimum, it's exclusive at the maximum. What if you need the results to be inclusive at both the minimum and the maximum? The <code>getRandomIntInclusive()</code> function below accomplishes that.</p> -<pre class="brush: js notranslate">function getRandomIntInclusive(min, max) { +<pre class="brush: js">function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1) + min); //The maximum is inclusive and the minimum is inclusive diff --git a/files/zh-tw/web/javascript/reference/global_objects/number/tofixed/index.html b/files/zh-tw/web/javascript/reference/global_objects/number/tofixed/index.html index addec4288b..99a2ef5dc6 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/number/tofixed/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/number/tofixed/index.html @@ -18,7 +18,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/toFixed <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate"><code><var>numObj</var>.toFixed([<var>digits</var>])</code></pre> +<pre class="syntaxbox"><code><var>numObj</var>.toFixed([<var>digits</var>])</code></pre> <h3 id="參數">參數</h3> @@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/toFixed <h3 id="Using_toFixed">Using <code>toFixed</code></h3> -<pre class="brush: js notranslate">var numObj = 12345.6789; +<pre class="brush: js">var numObj = 12345.6789; numObj.toFixed(); // Returns '12346': note rounding, no fractional part numObj.toFixed(1); // Returns '12345.7': note rounding diff --git a/files/zh-tw/web/javascript/reference/global_objects/object/assign/index.html b/files/zh-tw/web/javascript/reference/global_objects/object/assign/index.html index f4dfca5af7..65330a6196 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/object/assign/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/object/assign/index.html @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate">Object.assign(<var>target</var>, ...<var>sources</var>)</pre> +<pre class="syntaxbox">Object.assign(<var>target</var>, ...<var>sources</var>)</pre> <h3 id="參數">參數</h3> @@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign <h3 id="複製物件">複製物件</h3> -<pre class="brush: js notranslate">var obj = { a: 1 }; +<pre class="brush: js">var obj = { a: 1 }; var copy = Object.assign({}, obj); console.log(copy); // { a: 1 } </pre> @@ -49,7 +49,7 @@ console.log(copy); // { a: 1 } <p>深層複製(deep clone)需要使用其他的替代方案,因為 <code>Object.assign()</code> 僅複製屬性值。若來源物件的值參照到一個子物件,它只會複製該子物件的參照。</p> -<pre class="brush: js notranslate">function test() { +<pre class="brush: js">function test() { let a = { b: {c:4} , d: { e: {f:1}} } let g = Object.assign({},a) // 淺層 let h = JSON.parse(JSON.stringify(a)); // 深層 @@ -70,7 +70,7 @@ test(); <h3 id="合併物件">合併物件</h3> -<pre class="brush: js notranslate">var o1 = { a: 1 }; +<pre class="brush: js">var o1 = { a: 1 }; var o2 = { b: 2 }; var o3 = { c: 3 }; @@ -80,7 +80,7 @@ console.log(o1); // { a: 1, b: 2, c: 3 }, 目標物件本身也被改變。</pr <h3 id="有相同屬性時合併物件">有相同屬性時合併物件</h3> -<pre class="brush: js notranslate">var o1 = { a: 1, b: 1, c: 1 }; +<pre class="brush: js">var o1 = { a: 1, b: 1, c: 1 }; var o2 = { b: 2, c: 2 }; var o3 = { c: 3 }; @@ -91,7 +91,7 @@ console.log(obj); // { a: 1, b: 2, c: 3 },屬性c為o3.c的值,最後一個 <h3 id="複製_Symbol_型別的屬性">複製 Symbol 型別的屬性</h3> -<pre class="brush: js notranslate">var o1 = { a: 1 }; +<pre class="brush: js">var o1 = { a: 1 }; var o2 = { [Symbol('foo')]: 2 }; var obj = Object.assign({}, o1, o2); @@ -101,7 +101,7 @@ Object.getOwnPropertySymbols(obj); // [Symbol(foo)]非不在 <h3 id="在屬性鏈中的不可列舉屬性不會被複製">在屬性鏈中的不可列舉屬性不會被複製</h3> -<pre class="brush: js notranslate">var obj = Object.create({ foo: 1 }, { // foo 是 obj 的屬性鏈。 +<pre class="brush: js">var obj = Object.create({ foo: 1 }, { // foo 是 obj 的屬性鏈。 bar: { value: 2 // bar 是不可列舉的屬性,因為enumerable預設為false。 }, @@ -117,7 +117,7 @@ console.log(copy); // { baz: 3 } <h3 id="原始型別會被包成物件">原始型別會被包成物件</h3> -<pre class="brush: js notranslate">var v1 = 'abc'; +<pre class="brush: js">var v1 = 'abc'; var v2 = true; var v3 = 10; var v4 = Symbol('foo'); @@ -130,7 +130,7 @@ console.log(obj); // { "0": "a", "1": "b", "2": "c" } <h3 id="任何異常將會中斷正進行的複製程序">任何異常將會中斷正進行的複製程序</h3> -<pre class="brush: js notranslate">var target = Object.defineProperty({}, 'foo', { +<pre class="brush: js">var target = Object.defineProperty({}, 'foo', { value: 1, writable: false }); // target.foo 是 read-only (唯讀)屬性 @@ -148,7 +148,7 @@ console.log(target.baz); // undefined, 第三個來源物件也不會被複製 <h3 id="複製的存取程序">複製的存取程序</h3> -<pre class="brush: js notranslate">var obj = { +<pre class="brush: js">var obj = { foo: 1, get bar() { return 2; @@ -187,7 +187,7 @@ console.log(copy); <p>{{Glossary("Polyfill","polyfill")}} 不支援Symbol屬性,因為ES5沒有Symbol型別。</p> -<pre class="brush: js notranslate">if (typeof Object.assign != 'function') { +<pre class="brush: js">if (typeof Object.assign != 'function') { Object.assign = function (target, varArgs) { // .length of function is 2 'use strict'; if (target == null) { // TypeError if undefined or null diff --git a/files/zh-tw/web/javascript/reference/global_objects/object/index.html b/files/zh-tw/web/javascript/reference/global_objects/object/index.html index 3885c44a15..cf55c9b004 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/object/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/object/index.html @@ -15,7 +15,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate">// Object initialiser or literal +<pre class="syntaxbox">// Object initialiser or literal { [ <var>nameValuePair1</var>[, <var>nameValuePair2</var>[, ...<var>nameValuePairN</var>] ] ] } // Called as a constructor @@ -110,24 +110,24 @@ new Object([<var>value</var>])</pre> <p>下面例子儲存一個空物件至變數o</p> -<pre class="brush: js notranslate">var o = new Object(); +<pre class="brush: js">var o = new Object(); </pre> -<pre class="brush: js notranslate">var o = new Object(undefined); +<pre class="brush: js">var o = new Object(undefined); </pre> -<pre class="brush: js notranslate">var o = new Object(null); +<pre class="brush: js">var o = new Object(null); </pre> <h3 id="Using_Object_to_create_Boolean_objects">Using <code>Object</code> to create <code>Boolean</code> objects</h3> <p>下面例子儲存 {{jsxref("Boolean")}} 物件在 <code>o</code>:</p> -<pre class="brush: js notranslate">// equivalent to o = new Boolean(true); +<pre class="brush: js">// equivalent to o = new Boolean(true); var o = new Object(true); </pre> -<pre class="brush: js notranslate">// equivalent to o = new Boolean(false); +<pre class="brush: js">// equivalent to o = new Boolean(false); var o = new Object(Boolean()); </pre> 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 */ diff --git a/files/zh-tw/web/javascript/reference/global_objects/set/index.html b/files/zh-tw/web/javascript/reference/global_objects/set/index.html index 2b3f80fdd1..7875873120 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/set/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/set/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set <h2 id="語法">語法</h2> -<pre class="syntaxbox notranslate">new Set([<em>iterable</em>]);</pre> +<pre class="syntaxbox">new Set([<em>iterable</em>]);</pre> <h3 id="參數">參數</h3> @@ -67,7 +67,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set <h3 id="使用_Set_物件">使用 <code>Set</code> 物件</h3> -<pre class="brush: js notranslate">var mySet = new Set(); +<pre class="brush: js">var mySet = new Set(); mySet.add(1); // Set [ 1 ] mySet.add(5); // Set [ 1, 5 ] @@ -95,7 +95,7 @@ console.log(mySet);// Set [ 1, "some text", Object {a: 1, b: 2}, Object {a: 1, b <h3 id="迭代_Sets">迭代 Sets</h3> -<pre class="brush: js notranslate">// iterate over items in set +<pre class="brush: js">// iterate over items in set // logs the items in the order: 1, "some text", {"a": 1, "b": 2}, {"a": 1, "b": 2} for (let item of mySet) console.log(item); @@ -139,7 +139,7 @@ mySet.forEach(function(value) { <h3 id="實作基本的_set_操作">實作基本的 set 操作</h3> -<pre class="brush: js notranslate">Set.prototype.isSuperset = function(subset) { +<pre class="brush: js">Set.prototype.isSuperset = function(subset) { for (var elem of subset) { if (!this.has(elem)) { return false; @@ -188,7 +188,7 @@ setA.difference(setC); // => Set [1, 2] <h3 id="與_Array_物件關聯">與 <code>Array</code> 物件關聯</h3> -<pre class="brush: js notranslate">var myArray = ['value1', 'value2', 'value3']; +<pre class="brush: js">var myArray = ['value1', 'value2', 'value3']; // Use the regular Set constructor to transform an Array into a Set var mySet = new Set(myArray); @@ -200,7 +200,7 @@ console.log([...mySet]); // Will show you exactly the same Array as myArray</pre <h3 id="與_Strings_關聯">與 <code>Strings</code> 關聯</h3> -<pre class="brush: js notranslate">var text = 'India'; +<pre class="brush: js">var text = 'India'; var mySet = new Set(text); // Set ['I', 'n', 'd', 'i', 'a'] mySet.size; // 5 |