-
Notifications
You must be signed in to change notification settings - Fork 34
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
Translate Chapter of Typed Arrays #46
base: translate
Are you sure you want to change the base?
Changes from 1 commit
9b41d06
4f6a534
34c781b
64e6c24
18114fb
50f7b94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,34 +8,34 @@ | |
"id": "587d8253367417b2b2512c6a", | ||
"title": "Typed Arrays", | ||
"description": [ | ||
"Arrays are JavaScript objects that can hold a lot of different elements.", | ||
"数组是一种能存储各种数据类型的JavaScript对象。", | ||
"<code>var complexArr = [1, 5, \"2\", \"Word\", {\"name\": \"James\"}];</code>", | ||
"Basically what happens in the background is that your browser will automatically give the right amount of memory space for that array. It will also change as needed if you add or remove data.", | ||
"However, in the world of high performance and different element types, sometimes you need to be more specific on how much memory is given to an array.", | ||
"<dfn>Typed arrays</dfn> are the answer to this problem. You are now able to say how much memory you want to give an array. Below is a basic overview of the different types of arrays available and the size in bytes for each element in that array.", | ||
"<table class='table table-striped'><tr><th>Type</th><th>Each element size in bytes</th></tr><tr><td><code>Int8Array</code></td><td>1</td></tr><tr><td><code>Uint8Array</code></td><td>1</td></tr><tr><td><code>Uint8ClampedArray</code></td><td>1</td></tr><tr><td><code>Int16Array</code></td><td>2</td></tr><tr><td><code>Uint16Array</code></td><td>2</td></tr><tr><td><code>Int32Array</code></td><td>4</td></tr><tr><td><code>Uint32Array</code></td><td>4</td></tr><tr><td><code>Float32Array</code></td><td>4</td></tr><tr><td><code>Float64Array</code></td><td>8</td></tr></table>", | ||
"There are two ways in creating these kind of arrays. One way is to create it directly. Below is how to create a 3 length <code>Int16Array</code>.", | ||
"通常浏览器会自动的为数组分配合适的内存空间,同时内存大小也会随着你增删元素而发生变化。", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意标点,请使用全角逗号
注意 |
||
"然而,在一些对高性能有要求以及有不同数据类型的情况下,有时需要更精确地给一个数组分配内存空间。", | ||
"<dfn>Typed arrays</dfn> 就是解决这类问题的一种方案。 我们可以精确地给一个数组分配内存空间。如下列表说明了这种数组能够存放的数据类型以及不同数据类型所占据的字节数。", | ||
"<table class='table table-striped'><tr><th>类型</th><th>所占字节数</th></tr><tr><td><code>Int8Array</code></td><td>1</td></tr><tr><td><code>Uint8Array</code></td><td>1</td></tr><tr><td><code>Uint8ClampedArray</code></td><td>1</td></tr><tr><td><code>Int16Array</code></td><td>2</td></tr><tr><td><code>Uint16Array</code></td><td>2</td></tr><tr><td><code>Int32Array</code></td><td>4</td></tr><tr><td><code>Uint32Array</code></td><td>4</td></tr><tr><td><code>Float32Array</code></td><td>4</td></tr><tr><td><code>Float64Array</code></td><td>8</td></tr></table>", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"有两种方式可以创这类数组。其中一种是直接创建,如下代码创建了一个长度为3的 <code>Int16Array</code>.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"<blockquote>var i8 = new Int16Array(3);<br>console.log(i8);<br>// Returns [0, 0, 0]</blockquote>", | ||
"You can also create a <dfn>buffer</dfn> to assign how much data (in bytes) you want the array to take up.", | ||
"<strong>Note</strong><br>To create typed arrays using buffers, you need to assign the number of bytes to be a multiple of the bytes listed above.", | ||
"我们也可以通过创建 <dfn>buffer</dfn> 的方式来决定一个数组要容纳多少元素。", | ||
"<strong>提示</strong><br>我们可以通过分配对应长度字节数来创建一个和上方代码中一样的类型数组。", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
下同 注意,原文 |
||
"<blockquote>// Create same Int16Array array differently<br>var byteSize = 6; // Needs to be multiple of 2<br>var buffer = new ArrayBuffer(byteSize);<br>var i8View = new Int16Array(buffer);<br>buffer.byteLength; // Returns 6<br>i8View.byteLength; // Returns 6<br>console.log(i8View); // Returns [0, 0, 0]</blockquote>", | ||
"<dfn>Buffers</dfn> are general purpose objects that just carry data. You cannot access them normally. To access them, you need to first create a <dfn>view</dfn>.", | ||
"<dfn>Buffers</dfn> 是一类存储数据的特定类型对象。我们需要通过创建视图来访问这类对象,不能直接访问。", | ||
"<blockquote>i8View[0] = 42;<br>console.log(i8View); // Returns [42, 0, 0]</blockquote>", | ||
"<strong>Note</strong><br>Typed arrays do not have some of the methods traditional arrays have such as <code>.pop()</code> or <code>.push()</code>. Typed arrays also fail <code>Array.isArray()</code> that checks if something is an array. Although simpler, this can be an advantage for less-sophisticated JavaScript engines to implement them.", | ||
"<strong>提示</strong><br>Typed Arrays并没有像 <code>.pop()</code> 或 <code>.push()</code>这些一般数组拥有的方法。 使用 <code>Array.isArray()</code> 方法对Typed Arrays做判断返回的是fail,而非true。因为更加简洁,所以更便于简化JavaScript引擎去实现这类数组。", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意,全角半角之间加空格。
请仔细阅读 style-guide |
||
"<hr>", | ||
"First create a <code>buffer</code> that is 64-bytes. Then create a <code>Int32Array</code> typed array with a view of it called <code>i32View</code>." | ||
"先创建一个64个字节的 <code>buffer</code> , 再创建一个类型是 <code>Int32Array</code> 名称叫做 <code>i32View</code>的视图。" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 逗号之后多了个空格 |
||
], | ||
"tests": [ | ||
{ | ||
"text": "Your <code>buffer</code> should be 64 bytes large.", | ||
"text": " <code>buffer</code> 应该有64个字节的长度。", | ||
"testString": "assert(buffer.byteLength === 64, 'Your <code>buffer</code> should be 64 bytes large.');" | ||
}, | ||
{ | ||
"text": "Your <code>i32View</code> view of your buffer should be 64 bytes large.", | ||
"text": " <code>i32View</code> 视图应该有64个字节的长度。", | ||
"testString": "assert(i32View.byteLength === 64, 'Your <code>i32View</code> view of your buffer should be 64 bytes large.');" | ||
}, | ||
{ | ||
"text": "Your <code>i32View</code> view of your buffer should be 16 elements long.", | ||
"text": " <code>i32View</code> 视图应该能容纳16个元素。", | ||
"testString": "assert(i32View.length === 16, 'Your <code>i32View</code> view of your buffer should be 16 elements long.');" | ||
} | ||
], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaScript
两边要加空格。请参考 style-guide.md翻译建议:
数组是一种 JavaScript 对象,它可以存储多个不同类型的元素。