From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../sharedarraybuffer/slice/index.html | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice') diff --git a/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.html b/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.html new file mode 100644 index 0000000000..a13b9885f3 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/sharedarraybuffer/slice/index.html @@ -0,0 +1,76 @@ +--- +title: SharedArrayBuffer.prototype.slice() +slug: Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice +tags: + - SharedArrayBuffer + - slice +translation_of: Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice +--- +
{{JSRef}}
+ +

SharedArrayBuffer.prototype.slice() 方法返回一个新的{{jsxref("SharedArrayBuffer")}} 副本,其内容是该SharedArrayBuffer的字节从begin开始(包含begin),直到end结束(不包含end)。如果beginend是负的,它指的是从数组末尾开始的索引。此方法与 {{jsxref("Array.prototype.slice()")}} 具有相同的算法。

+ +

{{EmbedInteractiveExample("pages/js/sharedarraybuffer-slice.html")}}

+ +

语法

+ +
sab.slice()
+sab.slice(begin)
+sab.slice(begin, end)
+ +

参数

+ +
+
begin {{optional_inline}}
+
从零开始的索引,从该索引开始提取。
+
可以使用一个负索引,表示从序列末尾开始的偏移量。 slice(-2)提取序列中的最后两个元素。
+
If begin is undefined, slice begins from index 0.如果begin为undefined,slice则从索引为0处开始。
+
end {{optional_inline}}
+
从零开始的索引,在此索引之前终止提取。 slice 执行提取到索引为end的位置(不包含end)。
+
例如,slice(1,4)提取第二个元素到第四个元素(索引为1、2和3的元素)。
+
可以使用一个负索引,表示从序列末尾开始的偏移量。 slice(2,-1)提取序列中从第三个元素开始,到倒数第二个元素结束的全部元素。
+
如果省略end,则slice一直提取到序列的末尾(sab.byteLength)。
+
+ +

返回值

+ +

一个包含被提取出的元素的新 {{jsxref("SharedArrayBuffer")}} 。

+ +

例子

+ +
var sab = new SharedArrayBuffer(1024);
+sab.slice();    // SharedArrayBuffer { byteLength: 1024 }
+sab.slice(2);   // SharedArrayBuffer { byteLength: 1022 }
+sab.slice(-2);  // SharedArrayBuffer { byteLength: 2 }
+sab.slice(0, 1); // SharedArrayBuffer { byteLength: 1 }
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-sharedarraybuffer.prototype.slice', 'SharedArrayBuffer.prototype.slice')}}{{Spec2('ESDraft')}}Initial definition in ES2017.
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.SharedArrayBuffer.slice")}}

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf