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 --- .../reference/global_objects/array/length/index.html | 10 +++++----- .../reference/global_objects/array/slice/index.html | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'files/zh-tw/web/javascript/reference/global_objects/array') 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,
-- 
cgit v1.2.3-54-g00ecf