-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript之typed arrays那些事儿 #164
Comments
typed arrays基本介绍
|
Buffers和views:typed array 架构
ArrayBuffer
Typed array views
扩展: DataView
// create an ArrayBuffer with a size in bytes
var buffer = new ArrayBuffer(16);
// Create a couple of views
var view1 = new DataView(buffer);
var view2 = new DataView(buffer,12,4); //from byte 12 for the next 4 bytes
view1.setInt8(12, 42); // put 42 in slot 12
console.log(view1.buffer);
console.log(view2.buffer);
console.log(view1.getInt8(12));
console.log(view2.getInt8(0));
扩展: |
typed arrays的Web API使用了typed array的web api有以下这些。
interface mixin Body {
readonly attribute ReadableStream? body;
readonly attribute boolean bodyUsed;
[NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<Blob> blob();
[NewObject] Promise<FormData> formData();
[NewObject] Promise<any> json();
[NewObject] Promise<USVString> text();
}; 通过send方法发送二进制数据的最好方式是:ArrayBufferView或Blob。 拓展:interface mixin Body{}怎么理解?
IDL通常用js或者java实现。此处的interface mixin是java实现。
如何将 typedArray 转换为普通数组处理完typed array以后,很多情况下会将其转换为普通数组。 let typedArray = new Uint8Array([1, 2, 3, 4]);
let normalArray = Array.from(typedArray); let typedArray = new Uint8Array([1, 2, 3, 4]),
normalArray = Array.prototype.slice.call(typedArray);
normalArray.length === 4;
normalArray.constructor === Array; |
主要参考这篇文章:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
The text was updated successfully, but these errors were encountered: