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/slice/index.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'files/zh-tw/web/javascript/reference/global_objects/array/slice/index.html') 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