diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/domstring | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/domstring')
-rw-r--r-- | files/zh-cn/web/api/domstring/binary/index.html | 23 | ||||
-rw-r--r-- | files/zh-cn/web/api/domstring/index.html | 52 |
2 files changed, 75 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/domstring/binary/index.html b/files/zh-cn/web/api/domstring/binary/index.html new file mode 100644 index 0000000000..4eab745a82 --- /dev/null +++ b/files/zh-cn/web/api/domstring/binary/index.html @@ -0,0 +1,23 @@ +--- +title: Binary strings +slug: Web/API/DOMString/Binary +translation_of: Web/API/DOMString/Binary +--- +<p>{{jsxref("String", "JavaScript strings")}} 是 UTF-16 编码的字符串。它的一个子集是ASCII 字符集(i.e., 字符的码点不会超过 <code>127</code>)。比如, <code>"Hello world!"</code>这个字符串属于 ASCII 子集, 而 <code>"ÀÈÌÒÙ"</code> 不属于ASCII。binary string 是JS字符集的另外一个子集,它类似于 ASCII 字符集,但是字符的码点(charCode)不再限制到 <code>127</code>, 它包含了<code>255 </code>以内的字符。 binary string设计的目的不是用于代表字符, 而是代表二进制数据。由 binary string 代表的二进制数据大小是原始数据的两倍,然而这对于最终用户是不可见的, 因为JavaScript strings 的长度是以2字节为单位进行计算的。</p> + +<p>Binary strings 不是JavaScript 语言的设计。 然而至少有一个native 函数以它作为输入 ,比如{{domxref("WindowBase64.btoa","btoa()")}}: 给这个函数传入charcode 大于<code>255</code> 的字符串会抛出一个 <code>Character Out Of Range</code> 的错误。</p> + +<p>引入Binary strings来代表<code>uint8</code> 数字的原因是由于 web 应用变得越来越强大(比如操作音频和视频, 使用WebSockets获取二进制数据, 等等)很明显,有一种可以让JavaScript可以简单而快速地操作二进制数据的api 将会提供很大的帮助。</p> + +<p>在以前, 操作二进制数据必须通过对字符串的操作来模拟。使用 <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/charCodeAt" title="JavaScript/Reference/Global Objects/String/charCodeAt"><code>charCodeAt()</code></a> 方法从Binary strings读取数据. 然而这么做又慢又容易出错, 因为需要多次转换(尤其是当数据不是真正的 byte-format data,而是 32-bit 整数或者浮点数)。</p> + +<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays" title="/en-US/docs/Web/JavaScript/Typed_arrays">JavaScript typed arrays</a> 提供了一个操作 二进制数据更加高效的方法。<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays/StringView" title="/en-US/docs/Web/JavaScript/Typed_arrays/StringView"><code>StringView</code></a> 这个非 native的构造函数是构建在 typed arrays 上的为字符串提供了一个 <a href="http://en.wikipedia.org/wiki/C_%28programming_language%29">C</a>-like的接口。</p> + +<h2 id="参见">参见</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Typed_arrays" title="/en-US/docs/Web/JavaScript/Typed_arrays">Typed arrays</a></li> + <li><a href="/en-US/docs/Web/API/DOMString" title="/en-US/docs/Web/API/DOMString/Binary"><code>DOMString</code></a></li> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String" title="/en-US/docs/Web/API/DOMString">String</a></li> + <li><a href="/en-US/docs/Web/JavaScript/Typed_arrays/StringView" title="/en-US/docs/Web/JavaScript/Typed_arrays/String_view"><code>StringView</code></a></li> +</ul> diff --git a/files/zh-cn/web/api/domstring/index.html b/files/zh-cn/web/api/domstring/index.html new file mode 100644 index 0000000000..94ad3ad373 --- /dev/null +++ b/files/zh-cn/web/api/domstring/index.html @@ -0,0 +1,52 @@ +--- +title: DOMString +slug: Web/API/DOMString +tags: + - DOMString +translation_of: Web/API/DOMString +--- +<p>{{APIRef("DOM")}}</p> + +<p><strong><code>DOMString </code></strong>是一个UTF-16字符串。由于JavaScript已经使用了这样的字符串,所以DOMString 直接映射到 一个{{jsxref("String")}}。</p> + +<p>将 <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null">null</a></code>传递给接受DOMString的方法或参数时通常会把其stringifies为“null”。</p> + +<h2 id="Specification" name="Specification" style="margin-bottom: 20px; line-height: 30px;">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('WebIDL', '#DOMString', 'DOMString')}}</td> + <td>{{Spec2('WebIDL')}}</td> + <td>Rephrasing of the definition to remove weird edge cases.</td> + </tr> + <tr> + <td>{{SpecName('DOM3 Core', 'core.html#DOMString', 'DOMString')}}</td> + <td>{{Spec2('DOM3 Core')}}</td> + <td>No change from {{SpecName('DOM2 Core')}}</td> + </tr> + <tr> + <td>{{SpecName('DOM2 Core', 'core.html#ID-C74D1578', 'DOMString')}}</td> + <td>{{Spec2('DOM2 Core')}}</td> + <td>No change from {{SpecName('DOM1')}}</td> + </tr> + <tr> + <td>{{SpecName('DOM1', 'level-one-core.html#ID-C74D1578', 'DOMString')}}</td> + <td>{{Spec2('DOM1')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="相关链接" style="margin-bottom: 20px; line-height: 30px;">相关链接</h2> + +<ul> + <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String" title="/en-US/docs/Web/API/DOMString">String</a></li> + <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays/String_view" title="/en-US/docs/Web/JavaScript/Typed_arrays/String_view"><code>StringView</code> – a C-like representation of strings based on typed arrays</a></li> + <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString/Binary">Binary strings</a></li> +</ul> |