[英]forEach for Uint8ClampedArray
The getImageData function returns a special array object called Uint8ClampedArray
which inherits many of the familiar array methods. getImageData函数返回一个名为
Uint8ClampedArray
的特殊数组对象,它继承了许多熟悉的数组方法。 ForEach
points you to the generic method. ForEach
指向通用方法。
Let's try one: 我们来试试吧:
var g = new Uint8ClampedArray([1,2,3,4,5]);
undefined
g
[1, 2, 3, 4, 5]
g.forEach(function(x){ return x + 1; } )
undefined
g
[1, 2, 3, 4, 5]
Nothing happened. 没啥事儿。 The answer should be
[2,3,4,5,6]
what is wrong here? 答案应该是
[2,3,4,5,6]
这里有什么问题?
This was done in Chrome's JavaScript terminal -- in the developer tools. 这是在Chrome的JavaScript终端中完成的 - 在开发人员工具中。
Also I found this helpful: 我发现这有用:
The
Uint8ClampedArray
typed array represents an array of 8-bit unsigned integers clamped to 0-255;Uint8ClampedArray
类型数组表示一个8位无符号整数数组,钳位为0-255; if you specified a value that is out of the range of [0,255], 0 or 255 will be set instead.如果指定的值超出[0,255]范围,则将设置0或255。 The contents are initialized to 0. Once established, you can reference elements in the array using the object's methods, or using standard array index syntax (that is, using bracket notation).
内容初始化为0.一旦建立,您可以使用对象的方法或使用标准数组索引语法(即使用括号表示法)引用数组中的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.