From 6ca84f1794af830ada9736d7289ce29aabb04ca3 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:05 +0800 Subject: remove `notranslate` class in zh-TW --- .../global_objects/array/length/index.html | 10 +++++----- .../global_objects/array/slice/index.html | 14 +++++++------- .../global_objects/date/getday/index.html | 6 +++--- .../reference/global_objects/math/pow/index.html | 4 ++-- .../global_objects/math/random/index.html | 10 +++++----- .../global_objects/number/tofixed/index.html | 4 ++-- .../global_objects/object/assign/index.html | 22 +++++++++++----------- .../reference/global_objects/object/index.html | 12 ++++++------ .../reference/global_objects/proxy/index.html | 18 +++++++++--------- .../reference/global_objects/set/index.html | 12 ++++++------ 10 files changed, 56 insertions(+), 56 deletions(-) (limited to 'files/zh-tw/web/javascript/reference/global_objects') 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

length 為Array物件的屬性 ,可供設定或回傳該陣列實體中包含的元素個數。其值必為一大於零、32位元、且恆大於該陣列最大索引數的正整數。

-
var items = ['shoes', 'shirts', 'socks', 'sweaters'];
+
var items = ['shoes', 'shirts', 'socks', 'sweaters'];
 items.length;
 
 // returns 4
@@ -16,7 +16,7 @@ items.length;

length 屬性的值必為一正整數,其值必介於 0 ~ 232 (不包含)之間.

-
var namelistA = new Array(4294967296); //232 = 4294967296
+
var namelistA = new Array(4294967296); //232 = 4294967296
 var namelistC = new Array(-100) //負數
 
 console.log(namelistA.length); //RangeError: Invalid array length
@@ -32,7 +32,7 @@ console.log(namelistB.length);
 
 

你可以透過改變 length 屬性來改變陣列的長度。當你透過 length 屬性來增加陣列的長度時,陣列中實際的元素也會隨之增加。舉例來說,當你將 array.length 由 2 增加為3,則改動後該陣列即擁有3個元素,該新增的元素則會是一個不可迭代(non-iterable)的空槽(empty slot)。

-
const arr = [1, 2];
+
const arr = [1, 2];
 console.log(arr);
 // [ 1, 2 ]
 
@@ -62,7 +62,7 @@ arr.forEach(element => console.log(element)); // 空元素無法被迭代
 
 

以下範例中, 陣列 numbers 透過 length 屬性進行迭代操作,並將其內容值加倍。

-
var numbers = [1, 2, 3, 4, 5];
+
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++) {
 
 

以下範例中, 陣列 numbers  的長度若大於 3,則將其長度縮減至 3。

-
var numbers = [1, 2, 3, 4, 5];
+
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
 
 

語法

-
arr.slice([begin[, end]])
+
arr.slice([begin[, end]])
 

參數

@@ -56,7 +56,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Array/slice

Return a portion of an existing array

-
var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango'];
+
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);
 
 

In the following example, slice creates a new array, newCar, from myCar. Both include a reference to the object myHonda. When the color of myHonda is changed to purple, both arrays reflect the change.

-
// Using slice, create newCar from myCar.
+
// 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);
 
 

This script writes:

-
myCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2,
+
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
 
 

slice 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'.

-
function list() {
+
function list() {
   return Array.prototype.slice.call(arguments);
 }
 
@@ -113,7 +113,7 @@ var list1 = list(1, 2, 3); // [1, 2, 3]
 
 

Binding can be done with the .call function of {{jsxref("Function.prototype")}} and it can also be reduced using [].slice.call(arguments) instead of Array.prototype.slice.call. Anyway, it can be simplified using {{jsxref("Function.prototype.bind", "bind")}}.

-
var unboundSlice = Array.prototype.slice;
+
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]
 
 

Although host objects (such as DOM objects) are not required by spec to follow the Mozilla behavior when converted by Array.prototype.slice 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 de facto standard behavior. (The shim also fixes IE to work with the second argument of slice() 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.)

-
/**
+
/**
  * 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
 
 

語法

-
dateObj.getDay()
+
dateObj.getDay()

返回值

@@ -25,7 +25,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Date/getDay

下面第二行表示根據日期對象'Xmas95'的值,把1賦值給'weekday'。則1995年12月25日是星期一。

-
var Xmas95 = new Date('December 25, 1995 23:15:30');
+
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
 

Note: 如果需要,可以使用{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}加上options參數來獲取星期幾全名。使使用此方法能輕鬆做出各種國際語言:

-
var options = { weekday: 'long'};
+
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
 
 

語法

-
Math.pow(base, exponent)
+
Math.pow(base, exponent)

參數

@@ -36,7 +36,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/pow

使用 Math.pow()

-
// simple
+
// 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
 
 

語法

-
Math.random()
+
Math.random()

回傳值 Return value

@@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

Getting a random number between 0 (inclusive) and 1 (exclusive)

-
function getRandom() {
+
function getRandom() {
   return Math.random();
 }
 
@@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

This example returns a random number between the specified values. The returned value is no lower than (and may possibly equal) min, and is less than (and not equal) max.

-
function getRandomArbitrary(min, max) {
+
function getRandomArbitrary(min, max) {
   return Math.random() * (max - min) + min;
 }
 
@@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Math/random

This example returns a random integer between the specified values. The value is no lower than min (or the next integer greater than min if min isn't an integer), and is less than (but not equal to) max.

-
function getRandomInt(min, max) {
+
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
 
 

While the getRandomInt() 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 getRandomIntInclusive() function below accomplishes that.

-
function getRandomIntInclusive(min, max) {
+
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
 
 

語法

-
numObj.toFixed([digits])
+
numObj.toFixed([digits])

參數

@@ -48,7 +48,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Number/toFixed

Using toFixed

-
var numObj = 12345.6789;
+
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
 
 

語法

-
Object.assign(target, ...sources)
+
Object.assign(target, ...sources)

參數

@@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign

複製物件

-
var obj = { a: 1 };
+
var obj = { a: 1 };
 var copy = Object.assign({}, obj);
 console.log(copy); // { a: 1 }
 
@@ -49,7 +49,7 @@ console.log(copy); // { a: 1 }

深層複製(deep clone)需要使用其他的替代方案,因為 Object.assign() 僅複製屬性值。若來源物件的值參照到一個子物件,它只會複製該子物件的參照。

-
function test() {
+
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();
 
 

合併物件

-
var o1 = { a: 1 };
+
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 }, 目標物件本身也被改變。有相同屬性時合併物件
 
-
var o1 = { a: 1, b: 1, c: 1 };
+
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的值,最後一個
 
 

複製 Symbol 型別的屬性

-
var o1 = { a: 1 };
+
var o1 = { a: 1 };
 var o2 = { [Symbol('foo')]: 2 };
 
 var obj = Object.assign({}, o1, o2);
@@ -101,7 +101,7 @@ Object.getOwnPropertySymbols(obj); // [Symbol(foo)]非不在
 
 

在屬性鏈中的不可列舉屬性不會被複製

-
var obj = Object.create({ foo: 1 }, { // foo 是 obj 的屬性鏈。
+
var obj = Object.create({ foo: 1 }, { // foo 是 obj 的屬性鏈。
   bar: {
     value: 2  // bar 是不可列舉的屬性,因為enumerable預設為false。
   },
@@ -117,7 +117,7 @@ console.log(copy); // { baz: 3 }
 
 

原始型別會被包成物件

-
var v1 = 'abc';
+
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" }
 
 

任何異常將會中斷正進行的複製程序

-
var target = Object.defineProperty({}, 'foo', {
+
var target = Object.defineProperty({}, 'foo', {
   value: 1,
   writable: false
 }); // target.foo 是 read-only (唯讀)屬性
@@ -148,7 +148,7 @@ console.log(target.baz);  // undefined, 第三個來源物件也不會被複製
 
 

複製的存取程序

-
var obj = {
+
var obj = {
   foo: 1,
   get bar() {
     return 2;
@@ -187,7 +187,7 @@ console.log(copy);
 
 

{{Glossary("Polyfill","polyfill")}} 不支援Symbol屬性,因為ES5沒有Symbol型別。

-
if (typeof Object.assign != 'function') {
+
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
 
 

語法

-
// Object initialiser or literal
+
// Object initialiser or literal
 { [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }
 
 // Called as a constructor
@@ -110,24 +110,24 @@ new Object([value])

下面例子儲存一個空物件至變數o

-
var o = new Object();
+
var o = new Object();
 
-
var o = new Object(undefined);
+
var o = new Object(undefined);
 
-
var o = new Object(null);
+
var o = new Object(null);
 

Using Object to create Boolean objects

下面例子儲存 {{jsxref("Boolean")}} 物件在 o:

-
// equivalent to o = new Boolean(true);
+
// equivalent to o = new Boolean(true);
 var o = new Object(true);
 
-
// equivalent to o = new Boolean(false);
+
// equivalent to o = new Boolean(false);
 var o = new Object(Boolean());
 
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

語法

-
var p = new Proxy(target, handler);
+
var p = new Proxy(target, handler);
 

參數

@@ -58,7 +58,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Proxy

In this simple example the number 37 gets returned as the default value when the property name is not in the object. It is using the get handler.

-
var handler = {
+
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
 
 

In this example, we are using a native JavaScript object to which our proxy will forward all operations that are applied to it.

-
var target = {};
+
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
 
 

With a Proxy, you can easily validate the passed value for an object. This example uses the set handler.

-
let validator = {
+
let validator = {
   set: function(obj, prop, value) {
     if (prop === 'age') {
       if (!Number.isInteger(value)) {
@@ -120,7 +120,7 @@ person.age = 300; // Throws an exception

A function proxy could easily extend a constructor with a new constructor. This example uses the construct and apply handlers.

-
function extend(sup, base) {
+
function extend(sup, base) {
   var descriptor = Object.getOwnPropertyDescriptor(
     base.prototype, 'constructor'
   );
@@ -161,7 +161,7 @@ console.log(Peter.age);  // 13

Sometimes you want to toggle the attribute or class name of two different elements. Here's how using the set handler.

-
let view = new Proxy({
+
let view = new Proxy({
   selected: null
 },
 {
@@ -196,7 +196,7 @@ console.log(i2.getAttribute('aria-selected')); // 'true'

The products proxy object evaluates the passed value and convert it to an array if needed. The object also supports an extra property called latestBrowser both as a getter and a setter.

-
let products = new Proxy({
+
let products = new Proxy({
   browsers: ['Internet Explorer', 'Netscape']
 },
 {
@@ -241,7 +241,7 @@ console.log(products.latestBrowser); // 'Chrome'

This proxy extends an array with some utility features. As you see, you can flexibly "define" properties without using Object.defineProperties. This example can be adapted to find a table row by its cell. In that case, the target will be table.rows.

-
let products = new Proxy([
+
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
 
 

Now in order to create a complete sample traps list, for didactic purposes, we will try to proxify a non native object that is particularly suited to this type of operation: the docCookies global object created by the "little framework" published on the document.cookie page.

-
/*
+
/*
   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
 
 

語法

-
new Set([iterable]);
+
new Set([iterable]);

參數

@@ -67,7 +67,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Set

使用 Set 物件

-
var mySet = new Set();
+
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
 
 

迭代 Sets

-
// iterate over items in set
+
// 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) {
 
 

實作基本的 set 操作

-
Set.prototype.isSuperset = function(subset) {
+
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]
 
 

與 Array 物件關聯

-
var myArray = ['value1', 'value2', 'value3'];
+
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
與 Strings 關聯 -
var text = 'India';
+
var text = 'India';
 
 var mySet = new Set(text);  // Set ['I', 'n', 'd', 'i', 'a']
 mySet.size;  // 5
-- 
cgit v1.2.3-54-g00ecf