非常教程

JavaScript参考手册

TypedArray

typedArray.copyWithin

copyWithin()方法将数组中的元素序列复制到以target起始的位置。 副本取自第二个参数和第三个参数startend的位置下标。end参数是可选的,默认为数组长度。这个方法的算法和Array.prototype.copyWithin相同。TypedArray是这里的类型化数组类型之一。

语法

typedarray.copyWithin(target, start[, end = this.length])

参数

target目标起始位置的下标,复制元素到这里。start源起始位置的下标,在这里开始复制元素。end可选可选。源终止位置的下标,在这里停止复制元素。

返回值

修改后的类型化数组。

描述

更多信息请见Array.prototype.copyWithin

这个方法取代了实验性的TypedArray.prototype.move()

示例

var buffer = new ArrayBuffer(8);
var uint8 = new Uint8Array(buffer);
uint8.set([1,2,3]);
console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ]
uint8.copyWithin(3,0,3);
console.log(uint8); // Uint8Array [ 1, 2, 3, 1, 2, 3, 0, 0 ]

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'TypedArray.prototype.copyWithin' in that specification.

Standard

Initial definition.

ECMAScript 2017 Draft (ECMA-262)The definition of 'TypedArray.prototype.copyWithin' in that specification.

Draft

浏览器兼容性

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

45.0

34 (34)

No support

36.0

No support

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

No support

34.0 (34)

No support

No support

No support

JavaScript

JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络