diff options
Diffstat (limited to 'files/pl/web/javascript/reference/global_objects/dataview/index.html')
-rw-r--r-- | files/pl/web/javascript/reference/global_objects/dataview/index.html | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/files/pl/web/javascript/reference/global_objects/dataview/index.html b/files/pl/web/javascript/reference/global_objects/dataview/index.html new file mode 100644 index 0000000000..db3d459a82 --- /dev/null +++ b/files/pl/web/javascript/reference/global_objects/dataview/index.html @@ -0,0 +1,118 @@ +--- +title: DataView +slug: Web/JavaScript/Referencje/Obiekty/DataView +translation_of: Web/JavaScript/Reference/Global_Objects/DataView +--- +<div>{{JSRef}}</div> + +<p><strong><code>DataView</code></strong> udostępnia niskopoziowy interfejs do zapisu i odczytu typów numerycznych w formie {{jsxref("ArrayBuffer")}} niezależnie od kodowania platformy.</p> + +<h2 id="Składnia">Składnia</h2> + +<pre class="syntaxbox">new DataView(buffer [, byteOffset [, byteLength]])</pre> + +<h3 id="Parametry">Parametry</h3> + +<dl> + <dt><code>buffer</code></dt> + <dd>Istniejący {{jsxref("ArrayBuffer")}} lub {{jsxref("SharedArrayBuffer")}} {{experimental_inline}} używany jako pamięć dla obiektu <code>DataView</code> .</dd> + <dt><code>byteOffset</code> {{optional_inline}}</dt> + <dd>The offset, in bytes, to the first byte in the specified buffer for the new view to reference. If not specified, the view of the buffer will start with the first byte.</dd> + <dt><code>byteLength</code> {{optional_inline}}</dt> + <dd>The number of elements in the byte array. If unspecified, length of the view will match the buffer's length.</dd> +</dl> + +<h3 id="Return_value">Return value</h3> + +<p>A new <code>DataView</code> object representing the specified data buffer.</p> + +<h3 id="Exceptions">Exceptions</h3> + +<dl> + <dt><code>{{jsxref("RangeError")}}</code></dt> + <dd>Thrown if the <code>byteOffset</code> and <code>byteLength</code> result in the specified view extending past the end of the buffer.</dd> +</dl> + +<h2 id="Description">Description</h2> + +<h3 id="Endianness">Endianness</h3> + +<p>Multi-byte number formats are represented in memory differently depending on machine architecture, see {{Glossary("Endianness")}} for an explanation. DataView accessors provide explicit control of how data will be accessed irrespective of the platform architecture's endianness.</p> + +<pre class="brush: js">var littleEndian = (function() { + var buffer = new ArrayBuffer(2); + new DataView(buffer).setInt16(0, 256, true /* littleEndian */); + // Int16Array uses the platform's endianness. + return new Int16Array(buffer)[0] === 256; +})(); +console.log(littleEndian); // true or false +</pre> + +<h2 id="Properties">Properties</h2> + +<p>All <code>DataView</code> instances inherit from {{jsxref("DataView.prototype")}} and allows the addition of properties to all DataView objects.</p> + +<p>{{page('en-US/Web/JavaScript/Reference/Global_Objects/DataView/prototype','Properties')}}</p> + +<h2 id="Methods">Methods</h2> + +<p>{{page('en-US/Web/JavaScript/Reference/Global_Objects/DataView/prototype','Methods')}}</p> + +<h2 id="Example">Example</h2> + +<pre class="brush: js">var buffer = new ArrayBuffer(16); +var dv = new DataView(buffer, 0); + +dv.setInt16(1, 42); +dv.getInt16(1); //42 +</pre> + +<h2 id="Specifications">Specifications</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('Typed Array')}}</td> + <td>{{Spec2('Typed Array')}}</td> + <td>Superseded by ECMAScript 6</td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-dataview-constructor', 'DataView')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition in an ECMA standard</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-dataview-constructor', 'DataView')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("javascript.builtins.DataView")}}</p> + +<h2 id="Compatibility_notes">Compatibility notes</h2> + +<p>Starting with Firefox 40, <code>DataView</code> requires to be constructed with a {{jsxref("Operators/new", "new")}} operator. Calling <code>DataView()</code> as a function without <code>new</code>, will throw a {{jsxref("TypeError")}} from now on.</p> + +<pre class="brush: js example-bad">var dv = DataView(buffer, 0); +// TypeError: calling a builtin DataView constructor without new is forbidden</pre> + +<pre class="brush: js example-good">var dv = new DataView(buffer, 0);</pre> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a class="link-https" href="https://github.com/jDataView/jDataView">jDataView</a>: JavaScript library that polyfills and extends the <code>DataView</code> API to all browsers and Node.js.</li> + <li>{{jsxref("ArrayBuffer")}}</li> + <li>{{jsxref("SharedArrayBuffer")}}</li> +</ul> |