diff options
author | Peter Bengtsson <mail@peterbe.com> | 2021-07-15 13:01:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-15 13:01:50 -0400 |
commit | 037a4118c4324d39fdef8bd23f9dd21b02f50946 (patch) | |
tree | 22dac72fd38b56df6f2caf0fb7f21cb187179e76 /files/pl/web/javascript/reference | |
parent | 335d06b805fab26d8d4b3e1378e7722c12f715fe (diff) | |
download | translated-content-037a4118c4324d39fdef8bd23f9dd21b02f50946.tar.gz translated-content-037a4118c4324d39fdef8bd23f9dd21b02f50946.tar.bz2 translated-content-037a4118c4324d39fdef8bd23f9dd21b02f50946.zip |
delete pages that were never translated from en-US (pl, part 1) (#1549)
Diffstat (limited to 'files/pl/web/javascript/reference')
10 files changed, 0 insertions, 1898 deletions
diff --git a/files/pl/web/javascript/reference/deprecated_and_obsolete_features/index.html b/files/pl/web/javascript/reference/deprecated_and_obsolete_features/index.html deleted file mode 100644 index e937d7c66d..0000000000 --- a/files/pl/web/javascript/reference/deprecated_and_obsolete_features/index.html +++ /dev/null @@ -1,293 +0,0 @@ ---- -title: Przestarzałe własności i metody -slug: Web/JavaScript/Reference/Deprecated_and_obsolete_features -tags: - - Dokumentacja_JavaScript - - Dokumentacje - - JavaScript - - Strony_wymagające_dopracowania - - Wszystkie_kategorie -translation_of: Web/JavaScript/Reference/Deprecated_and_obsolete_features -original_slug: Web/JavaScript/Referencje/Przestarzałe_własności_i_metody ---- -<div>{{JsSidebar("More")}}</div> - -<p>This page lists features of JavaScript that are deprecated (that is, still available but planned for removal) and obsolete (that is, no longer usable).</p> - -<h2 id="Deprecated_features">Deprecated features</h2> - -<p>These deprecated features can still be used, but should be used with caution because they are expected to be removed entirely sometime in the future. You should work to remove their use from your code.</p> - -<h3 id="RegExp_properties">RegExp properties</h3> - -<p>The following properties are deprecated. This does not affect their use in {{jsxref("String.replace", "replacement strings", "", 1)}}:</p> - -<table class="standard-table"> - <tbody> - <tr> - <th>Property</th> - <th>Description</th> - </tr> - <tr> - <td>{{jsxref("RegExp.n", "$1-$9")}}</td> - <td> - <p>Parenthesized substring matches, if any.<br> - <strong>Warning:</strong> Using these properties can result in problems, since browser extensions can modify them. Avoid them!</p> - </td> - </tr> - <tr> - <td>{{jsxref("RegExp.input", "$_")}}</td> - <td>See <code>input</code>.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.multiline", "$*")}}</td> - <td>See <code>multiline</code>.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.lastMatch", "$&")}}</td> - <td>See <code>lastMatch</code>.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.lastParen", "$+")}}</td> - <td>See <code>lastParen</code>.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.leftContext", "$`")}}</td> - <td>See <code>leftContext</code>.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.rightContext", "$'")}}</td> - <td>See <code>rightContext</code>.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.input", "input")}}</td> - <td>The string against which a regular expression is matched.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.lastMatch", "lastMatch")}}</td> - <td>The last matched characters.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.lastParen", "lastParen")}}</td> - <td>The last parenthesized substring match, if any.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.leftContext", "leftContext")}}</td> - <td>The substring preceding the most recent match.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.rightContext", "rightContext")}}</td> - <td>The substring following the most recent match.</td> - </tr> - </tbody> -</table> - -<p>The following are now properties of <code>RegExp</code> instances, no longer of the <code>RegExp</code> object:</p> - -<table class="standard-table"> - <tbody> - <tr> - <th>Property</th> - <th>Description</th> - </tr> - <tr> - <td>{{jsxref("RegExp.global", "global")}}</td> - <td>Whether or not to test the regular expression against all possible matches in a string, or only against the first.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.ignoreCase", "ignoreCase")}}</td> - <td>Whether or not to ignore case while attempting a match in a string.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.lastIndex", "lastIndex")}}</td> - <td>The index at which to start the next match.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.multiline", "multiline")}}</td> - <td>Whether or not to search in strings across multiple lines.</td> - </tr> - <tr> - <td>{{jsxref("RegExp.source", "source")}}</td> - <td>The text of the pattern.</td> - </tr> - </tbody> -</table> - -<h3 id="RegExp_methods">RegExp methods</h3> - -<ul> - <li>The {{jsxref("RegExp.compile", "compile()")}} method is deprecated.</li> - <li>The <code>valueOf</code> method is no longer specialized for <code>RegExp</code>. Use {{jsxref("Object.valueOf()")}}.</li> -</ul> - -<h3 id="Function_properties">Function properties</h3> - -<ul> - <li>The {{jsxref("Global_Objects/Function/caller", "caller")}} and {{jsxref("Global_Objects/Function/arguments", "arguments")}} properties are deprecated, because they leak the function caller. Instead of the arguments property, you should use the {{jsxref("Functions/arguments", "arguments")}} object inside function closures.</li> -</ul> - -<h3 id="Legacy_generator">Legacy generator</h3> - -<ul> - <li>{{jsxref("Statements/Legacy_generator_function", "Legacy generator function statement")}} and {{jsxref("Operators/Legacy_generator_function", "Legacy generator function expression")}} are deprecated. Use {{jsxref("Statements/function*", "function* statement")}} and {{jsxref("Operators/function*", "function* expression")}} instead.</li> - <li>{{jsxref("Operators/Array_comprehensions", "JS1.7/JS1.8 Array comprehension", "#Differences_to_the_older_JS1.7.2FJS1.8_comprehensions")}} and {{jsxref("Operators/Generator_comprehensions", "JS1.7/JS1.8 Generator comprehension", "#Differences_to_the_older_JS1.7.2FJS1.8_comprehensions")}} are deprecated.</li> -</ul> - -<h3 id="Iterator">Iterator</h3> - -<ul> - <li>{{jsxref("Global_Objects/StopIteration", "StopIteration")}} is deprecated.</li> - <li>{{jsxref("Global_Objects/Iterator", "Iterator")}} is deprecated.</li> -</ul> - -<h3 id="Object_methods">Object methods</h3> - -<ul> - <li>{{jsxref("Object.watch", "watch")}} and {{jsxref("Object.unwatch", "unwatch")}} are deprecated. Use {{jsxref("Proxy")}} instead.</li> - <li><code>__iterator__</code> is deprecated.</li> - <li>{{jsxref("Object.noSuchMethod", "__noSuchMethod__")}} is deprecated. Use {{jsxref("Proxy")}} instead.</li> -</ul> - -<h3 id="Date_methods">Date methods</h3> - -<ul> - <li>{{jsxref("Global_Objects/Date/getYear", "getYear")}} and {{jsxref("Global_Objects/Date/setYear", "setYear")}} are affected by the Year-2000-Problem and have been subsumed by {{jsxref("Global_Objects/Date/getFullYear", "getFullYear")}} and {{jsxref("Global_Objects/Date/setFullYear", "setFullYear")}}.</li> - <li>You should use {{jsxref("Global_Objects/Date/toISOString", "toISOString")}} instead of the deprecated {{jsxref("Global_Objects/Date/toGMTString", "toGMTString")}} method in new code.</li> - <li>{{jsxref("Global_Objects/Date/toLocaleFormat", "toLocaleFormat")}} is deprecated.</li> -</ul> - -<h3 id="Functions">Functions</h3> - -<ul> - <li>{{jsxref("Operators/Expression_closures", "Expression closures", "", 1)}} are deprecated. Use regular {{jsxref("Operators/function", "functions")}} or {{jsxref("Functions/Arrow_functions", "arrow functions", "", 1)}} instead.</li> -</ul> - -<h3 id="Proxy">Proxy</h3> - -<ul> - <li><a href="/en-US/docs/Archive/Web/Old_Proxy_API">Proxy.create</a> and <a href="/en-US/docs/Archive/Web/Old_Proxy_API">Proxy.createFunction</a> are deprecated. Use {{jsxref("Proxy")}} instead.</li> - <li>The following traps are obsolete: - <ul> - <li><code>hasOwn</code> ({{bug(980565)}}, Firefox 33).</li> - <li><code>getEnumerablePropertyKeys</code> ({{bug(783829)}}, Firefox 37)</li> - <li><code>getOwnPropertyNames</code> ({{bug(1007334)}}, Firefox 33)</li> - <li><code>keys</code> ({{bug(1007334)}}, Firefox 33)</li> - </ul> - </li> -</ul> - -<h3 id="Escape_sequences">Escape sequences</h3> - -<ul> - <li>Octal escape sequences (\ followed by one, two, or three octal digits) are deprecated in string and regular expression literals.</li> - <li>The {{jsxref("Global_Objects/escape", "escape")}} and {{jsxref("Global_Objects/unescape", "unescape")}} functions are deprecated. Use {{jsxref("Global_Objects/encodeURI", "encodeURI")}}, {{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent")}}, {{jsxref("Global_Objects/decodeURI", "decodeURI")}} or {{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent")}} to encode and decode escape sequences for special characters.</li> -</ul> - -<h3 id="String_methods">String methods</h3> - -<ul> - <li><a href="https://developer.mozilla.org/en-US/docs/tag/HTML%20wrapper%20methods">HTML wrapper methods</a> like {{jsxref("String.prototype.fontsize")}} and {{jsxref("String.prototype.big")}}.</li> - <li>{{jsxref("String.prototype.quote")}} is removed from Firefox 37.</li> - <li>non standard <code>flags</code> parameter in {{jsxref("String.prototype.search")}}, {{jsxref("String.prototype.match")}}, and {{jsxref("String.prototype.replace")}} are deprecated.</li> -</ul> - -<h2 id="Obsolete_features">Obsolete features</h2> - -<p>These obsolete features have been entirely removed from JavaScript and can no longer be used as of the indicated version of JavaScript.</p> - -<h3 id="Object">Object</h3> - -<table class="standard-table"> - <tbody> - <tr> - <th>Property</th> - <th>Description</th> - </tr> - <tr> - <td>{{jsxref("Global_Objects/Object/count", "__count__")}}</td> - <td>Returns the number of enumerable properties directly on a user-defined object.</td> - </tr> - <tr> - <td>{{jsxref("Global_Objects/Object/Parent", "__parent__")}}</td> - <td>Points to an object's context.</td> - </tr> - <tr> - <td>{{jsxref("Global_Objects/Object/eval", "Object.prototype.eval()")}}</td> - <td>Evaluates a string of JavaScript code in the context of the specified object.</td> - </tr> - <tr> - <td>{{jsxref("Object.observe()")}}</td> - <td>Asynchronously observing the changes to an object.</td> - </tr> - <tr> - <td>{{jsxref("Object.unobserve()")}}</td> - <td>Remove observers.</td> - </tr> - <tr> - <td>{{jsxref("Object.getNotifier()")}}</td> - <td>Creates an object that allows to synthetically trigger a change.</td> - </tr> - </tbody> -</table> - -<h3 id="Function">Function</h3> - -<table class="standard-table"> - <tbody> - <tr> - <th>Property</th> - <th>Description</th> - </tr> - <tr> - <td>{{jsxref("Global_Objects/Function/arity", "arity")}}</td> - <td>Number of formal arguments.</td> - </tr> - </tbody> -</table> - -<h3 id="Array">Array</h3> - -<table class="standard-table"> - <tbody> - <tr> - <td>Property</td> - <td>Description</td> - </tr> - <tr> - <td>{{jsxref("Array.observe()")}}</td> - <td>Asynchronously observing changes to Arrays.</td> - </tr> - <tr> - <td>{{jsxref("Array.unobserve()")}}</td> - <td>Remove observers.</td> - </tr> - </tbody> -</table> - -<h3 id="Number">Number</h3> - -<ul> - <li>{{jsxref("Number.toInteger()")}}</li> -</ul> - -<h3 id="ParallelArray">ParallelArray</h3> - -<ul> - <li>{{jsxref("ParallelArray")}}</li> -</ul> - -<h3 id="Statements">Statements</h3> - -<ul> - <li>{{jsxref("Statements/for_each...in", "for each...in")}} is deprecated. Use {{jsxref("Statements/for...of", "for...of")}} instead.</li> - <li>Destructuring {{jsxref("Statements/for...in", "for...in")}} is deprecated. Use {{jsxref("Statements/for...of", "for...of")}} instead.</li> - <li>let blocks and let expressions are obsolete.</li> -</ul> - -<h3 id="E4X">E4X</h3> - -<p>See <a href="/en-US/docs/Archive/Web/E4X">E4X</a> for more information.</p> - -<h3 id="Sharp_variables">Sharp variables</h3> - -<p>See <a href="/en-US/docs/Archive/Web/Sharp_variables_in_JavaScript">Sharp variables in JavaScript</a> for more information.</p> diff --git a/files/pl/web/javascript/reference/global_objects/escape/index.html b/files/pl/web/javascript/reference/global_objects/escape/index.html deleted file mode 100644 index 2fcf67431d..0000000000 --- a/files/pl/web/javascript/reference/global_objects/escape/index.html +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: escape() -slug: Web/JavaScript/Reference/Global_Objects/escape -translation_of: Web/JavaScript/Reference/Global_Objects/escape -original_slug: Web/JavaScript/Referencje/Obiekty/escape ---- -<div>{{jsSidebar("Objects")}}</div> - -<p>The deprecated <code><strong>escape()</strong></code> function computes a new string in which certain characters have been replaced by a hexadecimal escape sequence. Use {{jsxref("encodeURI")}} or {{jsxref("encodeURIComponent")}} instead.</p> - -<h2 id="Składnia">Składnia</h2> - -<pre class="syntaxbox"><code>escape(str)</code></pre> - -<h3 id="Parametry">Parametry</h3> - -<dl> - <dt><code>str</code></dt> - <dd>A string to be encoded.</dd> -</dl> - -<h2 id="Description">Description</h2> - -<p>The <code>escape</code> function is a property of the <em>global object</em>. Special characters are encoded with the exception of: @*_+-./</p> - -<p>The hexadecimal form for characters, whose code unit value is 0xFF or less, is a two-digit escape sequence: %xx. For characters with a greater code unit, the four-digit format %<strong>u</strong>xxxx is used.</p> - -<h2 id="Przykłady">Przykłady</h2> - -<pre class="brush: js">escape("abc123"); // "abc123" -escape("äöü"); // "%E4%F6%FC" -escape("ć"); // "%u0107" - -// znaki specjalne -escape("@*_+-./"); // "@*_+-./"</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('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-B.2.1', 'escape')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Defined in the (informative) Compatibility Annex B</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-escape-string', 'escape')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<p>{{CompatibilityTable}}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("encodeURI")}}</li> - <li>{{jsxref("encodeURIComponent")}}</li> -</ul> diff --git a/files/pl/web/javascript/reference/global_objects/generator/index.html b/files/pl/web/javascript/reference/global_objects/generator/index.html deleted file mode 100644 index a84467e7ca..0000000000 --- a/files/pl/web/javascript/reference/global_objects/generator/index.html +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: Generator -slug: Web/JavaScript/Reference/Global_Objects/Generator -translation_of: Web/JavaScript/Reference/Global_Objects/Generator -original_slug: Web/JavaScript/Referencje/Obiekty/Generator ---- -<div>{{JSRef}}</div> - -<p>Obiekt <code><strong>Generator</strong></code> jest zwracany przez {{jsxref("Polecenia/function*", "generator function", "", 1)}} i odpowiada obu: <a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable">iterable protocol</a> i <a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterator">iterator protocol</a>.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox">function* gen() { - yield 1; - yield 2; - yield 3; -} - -var g = gen(); // "Generator { }"</pre> - -<h2 id="Methods">Methods</h2> - -<dl> - <dt>{{jsxref("Generator.prototype.next()")}}</dt> - <dd>Returns a value yielded by the {{jsxref("Operators/yield", "yield")}} expression.</dd> - <dt>{{jsxref("Generator.prototype.return()")}}</dt> - <dd>Returns the given value and finishes the generator.</dd> - <dt>{{jsxref("Generator.prototype.throw()")}}</dt> - <dd>Throws an error to a generator.</dd> -</dl> - -<h2 id="Example">Example</h2> - -<h3 id="An_infinite_iterator">An infinite iterator</h3> - -<pre class="brush: js">function* idMaker() { - var index = 0; - while(true) - yield index++; -} - -var gen = idMaker(); // "Generator { }" - -console.log(gen.next().value); // 0 -console.log(gen.next().value); // 1 -console.log(gen.next().value); // 2 -// ...</pre> - -<h2 id="Legacy_generator_objects">Legacy generator objects</h2> - -<p>Firefox (SpiderMonkey) also implements an earlier version of generators in <a href="/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7">JavaScript 1.7</a>, where the star (*) in the function declaration was not necessary (you just use the <code>yield</code> keyword in the function body). However, legacy generators are deprecated. Do not use them; they are going to be removed ({{bug(1083482)}}).</p> - -<h3 id="Legacy_generator_methods">Legacy generator methods</h3> - -<dl> - <dt><code>Generator.prototype.next() </code>{{non-standard_inline}}</dt> - <dd>Returns a value yielded by the {{jsxref("Operatory/yield", "yield")}} expression. This corresponds to <code>next()</code> in the ES2015 generator object.</dd> - <dt><code>Generator.prototype.close()</code> {{non-standard_inline}}</dt> - <dd>Closes the generator, so that when calling <code>next()</code> an {{jsxref("StopIteration")}} error will be thrown. This corresponds to the <code>return()</code> method in the ES2015 generator object.</dd> - <dt><code>Generator.prototype.send()</code> {{non-standard_inline}}</dt> - <dd>Used to send a value to a generator. The value is returned from the {{jsxref("Operatory/yield", "yield")}} expression, and returns a value yielded by the next {{jsxref("Operatory/yield", "yield")}} expression. <code>send(x)</code> corresponds to <code>next(x)</code> in the ES2015 generator object.</dd> - <dt><strong><code>Generator.</code></strong><code>prototype.</code><strong><code>throw()</code> </strong> {{non-standard_inline}}</dt> - <dd>Throws an error to a generator. This corresponds to the <code>throw()</code> method in the ES2015 generator object.</dd> -</dl> - -<h3 id="Legacy_generator_example">Legacy generator example</h3> - -<pre class="brush: js">function fibonacci() { - var a = yield 1; - yield a * 2; -} - -var it = fibonacci(); -console.log(it); // "Generator { }" -console.log(it.next()); // 1 -console.log(it.send(10)); // 20 -console.log(it.close()); // undefined -console.log(it.next()); // throws StopIteration (as the generator is now closed) -</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('ES2015', '#sec-generator-objects', 'Generator objects')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-generator-objects', 'Generator objects')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<p>{{CompatibilityTable}}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatChrome(39.0)}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Android Webview</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - <th>Chrome for Android</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatNo}}</td> - <td>{{CompatChrome(39.0)}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatChrome(39.0)}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<h3 id="Legacy_generators">Legacy generators</h3> - -<ul> - <li>{{jsxref("Statements/Legacy_generator_function", "The legacy generator function", "", 1)}}</li> - <li>{{jsxref("Operators/Legacy_generator_function", "The legacy generator function expression", "", 1)}}</li> - <li>{{jsxref("StopIteration")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features/The_legacy_Iterator_protocol">The legacy Iterator protocol</a></li> -</ul> - -<h3 id="ES2015_generators">ES2015 generators</h3> - -<ul> - <li>{{jsxref("Functions", "Functions", "", 1)}}</li> - <li>{{jsxref("Statements/function", "function")}}</li> - <li>{{jsxref("Operators/function", "function expression")}}</li> - <li>{{jsxref("Function")}}</li> - <li>{{jsxref("Statements/function*", "function*")}}</li> - <li>{{jsxref("Operators/function*", "function* expression")}}</li> - <li>{{jsxref("GeneratorFunction")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">The Iterator protocol</a></li> -</ul> diff --git a/files/pl/web/javascript/reference/global_objects/string/blink/index.html b/files/pl/web/javascript/reference/global_objects/string/blink/index.html deleted file mode 100644 index 7430744309..0000000000 --- a/files/pl/web/javascript/reference/global_objects/string/blink/index.html +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: String.prototype.blink() -slug: Web/JavaScript/Reference/Global_Objects/String/blink -tags: - - Deprecated - - JavaScript - - Method - - Prototype - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/blink -original_slug: Web/JavaScript/Referencje/Obiekty/String/blink ---- -<div>{{JSRef}} {{deprecated_header}}</div> - -<h2 id="Podsumowanie" name="Podsumowanie">Podsumowanie</h2> - -<p>Powoduje, iż łańcuch będzie migotał tak, jakby był on wewnątrz znacznika {{HTMLElement("blink")}}.</p> - -<div class="warning"> -<p><strong>Warning:</strong> Blinking text is frowned upon by several accessibility standards. The <code><blink></code> element itself is non-standard and deprecated!</p> -</div> - -<h2 id="Sk.C5.82adnia" name="Sk.C5.82adnia">Składnia</h2> - -<pre class="syntaxbox"><code><var>str</var>.blink()</code></pre> - -<h2 id="Opis" name="Opis">Opis</h2> - -<p>The <code>blink()</code> method embeds a string in a <code><blink></code> tag: <code>"<blink>str</blink>"</code>.</p> - -<h2 id="Przyk.C5.82ady" name="Przyk.C5.82ady">Przykłady</h2> - -<h3 id="Przyk.C5.82ad:_Zastosowanie_metody_string_do_zmiany_formatowania_.C5.82a.C5.84cucha_znak.C3.B3w" name="Przyk.C5.82ad:_Zastosowanie_metody_string_do_zmiany_formatowania_.C5.82a.C5.84cucha_znak.C3.B3w">Przykład: Zastosowanie <code>blink()</code></h3> - -<p>Następujący przykład stosuje metodę string do zmiany formatowania łańcucha znaków:</p> - -<pre class="brush: js">var worldString="Witaj, Świecie"; - -console.log(worldString.blink()); // <blink>Witaj, Świecie</blink> -console.log(worldString.bold()); // <bold>Witaj, Świecie</bold> -console.log(worldString.italics()); // <i>Witaj, Świecie</i> -console.log(worldString.strike()); // <s>Witaj, Świecie</s> -</pre> - -<h2 id="Zobacz_tak.C5.BCe" name="Zobacz_tak.C5.BCe">Zobacz także</h2> - -<ul> - <li>{{jsxref("String.prototype.bold()")}}</li> - <li>{{jsxref("String.prototype.italics()")}}</li> - <li>{{jsxref("String.prototype.strike()")}}</li> -</ul> diff --git a/files/pl/web/javascript/reference/global_objects/string/fromcodepoint/index.html b/files/pl/web/javascript/reference/global_objects/string/fromcodepoint/index.html deleted file mode 100644 index 0a3bacc072..0000000000 --- a/files/pl/web/javascript/reference/global_objects/string/fromcodepoint/index.html +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: String.fromCodePoint() -slug: Web/JavaScript/Reference/Global_Objects/String/fromCodePoint -translation_of: Web/JavaScript/Reference/Global_Objects/String/fromCodePoint -original_slug: Web/JavaScript/Referencje/Obiekty/String/fromCodePoint ---- -<div>{{JSRef}}</div> - -<p>The static <strong><code>String.fromCodePoint()</code></strong> method returns a string created by using the specified sequence of code points.</p> - -<div>{{EmbedInteractiveExample("pages/js/string-fromcodepoint.html","shorter")}}</div> - - - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox notranslate">String<code>.fromCodePoint(<var>num1</var>[, ...[, <var>numN</var>]])</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code><var>num1</var>, ..., <var>numN</var></code></dt> - <dd>A sequence of code points.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p>A string created by using the specified sequence of code points.</p> - -<h3 id="Exceptions">Exceptions</h3> - -<ul> - <li>A {{jsxref("Errors/Not_a_codepoint", "RangeError")}} is thrown if an invalid Unicode code point is given (e.g. <code>"RangeError: NaN is not a valid code point"</code>).</li> -</ul> - -<h2 id="Description">Description</h2> - -<p>This method returns a string (and <em>not</em> a {{jsxref("String")}} object).</p> - -<p>Because <code>fromCodePoint()</code> is a static method of {{jsxref("String")}}, you must call it as <code>String.fromCodePoint()</code>, rather than as a method of a {{jsxref("String")}} object you created.</p> - -<h2 id="Polyfill">Polyfill</h2> - -<p>The <code>String.fromCodePoint()</code> method has been added to ECMAScript 2015 and may not be supported in all web browsers or environments yet.</p> - -<p>Use the code below for a polyfill:</p> - -<pre class="brush: js notranslate">if (!String.fromCodePoint) (function(stringFromCharCode) { - var fromCodePoint = function(_) { - var codeUnits = [], codeLen = 0, result = ""; - for (var index=0, len = arguments.length; index !== len; ++index) { - var codePoint = +arguments[index]; - // correctly handles all cases including `NaN`, `-Infinity`, `+Infinity` - // The surrounding `!(...)` is required to correctly handle `NaN` cases - // The (codePoint>>>0) === codePoint clause handles decimals and negatives - if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint)) - throw RangeError("Invalid code point: " + codePoint); - if (codePoint <= 0xFFFF) { // BMP code point - codeLen = codeUnits.push(codePoint); - } else { // Astral code point; split in surrogate halves - // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - codePoint -= 0x10000; - codeLen = codeUnits.push( - (codePoint >> 10) + 0xD800, // highSurrogate - (codePoint % 0x400) + 0xDC00 // lowSurrogate - ); - } - if (codeLen >= 0x3fff) { - result += stringFromCharCode.apply(null, codeUnits); - codeUnits.length = 0; - } - } - return result + stringFromCharCode.apply(null, codeUnits); - }; - try { // IE 8 only supports `Object.defineProperty` on DOM elements - Object.defineProperty(String, "fromCodePoint", { - "value": fromCodePoint, "configurable": true, "writable": true - }); - } catch(e) { - String.fromCodePoint = fromCodePoint; - } -}(String.fromCharCode)); -</pre> - -<h2 id="Examples">Examples</h2> - -<h3 id="Using_fromCodePoint">Using <code>fromCodePoint()</code></h3> - -<p>Valid input:</p> - -<pre class="brush: js notranslate">String.fromCodePoint(42); // "*" -String.fromCodePoint(65, 90); // "AZ" -String.fromCodePoint(0x404); // "\u0404" == "Є" -String.fromCodePoint(0x2F804); // "\uD87E\uDC04" -String.fromCodePoint(194564); // "\uD87E\uDC04" -String.fromCodePoint(0x1D306, 0x61, 0x1D307); // "\uD834\uDF06a\uD834\uDF07" -</pre> - -<p>Invalid input:</p> - -<pre class="brush: js notranslate">String.fromCodePoint('_'); // RangeError -String.fromCodePoint(Infinity); // RangeError -String.fromCodePoint(-1); // RangeError -String.fromCodePoint(3.14); // RangeError -String.fromCodePoint(3e-2); // RangeError -String.fromCodePoint(NaN); // RangeError -</pre> - -<h3 id="Compared_to_fromCharCode">Compared to <code>fromCharCode()</code></h3> - -<p>{{jsxref("String.fromCharCode()")}} cannot return supplementary characters (i.e. code points <code>0x010000</code> – <code>0x10FFFF</code>) by specifying their code point. Instead, it requires the UTF-16 surrogate pair in order to return a supplementary character:</p> - -<pre class="brush: js notranslate">String.fromCharCode(0xD83C, 0xDF03); // Code Point U+1F303 "Night with -String.fromCharCode(55356, 57091); // Stars" == "\uD83C\uDF03" -</pre> - -<p><code>String.fromCodePoint()</code>, on the other hand, can return 4-byte supplementary characters, as well as the more common 2-byte BMP characters, by specifying their code point (which is equivalent to the UTF-32 code unit):</p> - -<pre class="brush: js notranslate">String.fromCodePoint(0x1F303); // or 127747 in decimal -</pre> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specification</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.fromcodepoint', 'String.fromCodePoint')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<p>{{Compat("javascript.builtins.String.fromCodePoint")}}</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("String.fromCharCode()")}}</li> - <li>{{jsxref("String.prototype.charAt()")}}</li> - <li>{{jsxref("String.prototype.codePointAt()")}}</li> - <li>{{jsxref("String.prototype.charCodeAt()")}}</li> -</ul> diff --git a/files/pl/web/javascript/reference/global_objects/string/repeat/index.html b/files/pl/web/javascript/reference/global_objects/string/repeat/index.html deleted file mode 100644 index a6542a4bb7..0000000000 --- a/files/pl/web/javascript/reference/global_objects/string/repeat/index.html +++ /dev/null @@ -1,167 +0,0 @@ ---- -title: String.prototype.repeat() -slug: Web/JavaScript/Reference/Global_Objects/String/repeat -translation_of: Web/JavaScript/Reference/Global_Objects/String/repeat -original_slug: Web/JavaScript/Referencje/Obiekty/String/repeat ---- -<div>{{JSRef}}</div> - -<p>The <strong><code>repeat()</code></strong> method constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.</p> - -<h2 id="Składnia">Składnia</h2> - -<pre class="syntaxbox"><var>str</var>.repeat(<var>count</var>)</pre> - -<h3 id="Parametry">Parametry</h3> - -<dl> - <dt><code>count</code></dt> - <dd>An integer between 0 and +∞: [0, +∞), indicating the number of times to repeat the string in the newly-created string that is to be returned.</dd> -</dl> - -<h3 id="Zwracana_wartość">Zwracana wartość</h3> - -<p>A new string containing the specified number of copies of the given string.</p> - -<h3 id="Exceptions">Exceptions</h3> - -<ul> - <li>{{jsxref("Errors/Negative_repetition_count", "RangeError")}}: repeat count must be non-negative.</li> - <li>{{jsxref("Errors/Resulting_string_too_large", "RangeError")}}: repeat count must be less than infinity and not overflow maximum string size.</li> -</ul> - -<h2 id="Przykłady">Przykłady</h2> - -<pre class="brush: js">'abc'.repeat(-1); // RangeError -'abc'.repeat(0); // '' -'abc'.repeat(1); // 'abc' -'abc'.repeat(2); // 'abcabc' -'abc'.repeat(3.5); // 'abcabcabc' (count will be converted to integer) -'abc'.repeat(1/0); // RangeError - -({ toString: () => 'abc', repeat: String.prototype.repeat }).repeat(2); -// 'abcabc' (repeat() is a generic method) -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>This method has been added to the ECMAScript 6 specification and may not be available in all JavaScript implementations yet. However, you can polyfill <code>String.prototype.repeat()</code> with the following snippet:</p> - -<pre class="brush: js">if (!String.prototype.repeat) { - String.prototype.repeat = function(count) { - 'use strict'; - if (this == null) { - throw new TypeError('can\'t convert ' + this + ' to object'); - } - var str = '' + this; - count = +count; - if (count != count) { - count = 0; - } - if (count < 0) { - throw new RangeError('repeat count must be non-negative'); - } - if (count == Infinity) { - throw new RangeError('repeat count must be less than infinity'); - } - count = Math.floor(count); - if (str.length == 0 || count == 0) { - return ''; - } - // Ensuring count is a 31-bit integer allows us to heavily optimize the - // main part. But anyway, most current (August 2014) browsers can't handle - // strings 1 << 28 chars or longer, so: - if (str.length * count >= 1 << 28) { - throw new RangeError('repeat count must not overflow maximum string size'); - } - var rpt = ''; - for (;;) { - if ((count & 1) == 1) { - rpt += str; - } - count >>>= 1; - if (count == 0) { - break; - } - str += str; - } - // Could we try: - // return Array(count + 1).join(this); - return rpt; - } -} -</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('ES6', '#sec-string.prototype.repeat', 'String.prototype.repeat')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.repeat', 'String.prototype.repeat')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatChrome("41")}} </td> - <td>{{CompatGeckoDesktop("24")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatSafari("9")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatNo}}</td> - <td>{{CompatChrome("36")}}</td> - <td>{{CompatGeckoMobile("24")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - </tr> - </tbody> -</table> -</div> diff --git a/files/pl/web/javascript/reference/global_objects/uint16array/index.html b/files/pl/web/javascript/reference/global_objects/uint16array/index.html deleted file mode 100644 index 759ad9d56e..0000000000 --- a/files/pl/web/javascript/reference/global_objects/uint16array/index.html +++ /dev/null @@ -1,225 +0,0 @@ ---- -title: Uint16Array -slug: Web/JavaScript/Reference/Global_Objects/Uint16Array -translation_of: Web/JavaScript/Reference/Global_Objects/Uint16Array -original_slug: Web/JavaScript/Referencje/Obiekty/Uint16Array ---- -<div>{{JSRef("Global_Objects", "TypedArray", "Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array")}}</div> - -<h2 id="Summary">Summary</h2> - -<p>The <strong><code>Uint16Array</code></strong> typed array represents an array of 16-bit unsigned integers in the platform byte order. If control over byte order is needed, use {{jsxref("DataView")}} instead. The contents are initialized to <code>0</code>. 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).</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox">Uint16Array(length); -Uint16Array(typedArray); -Uint16Array(object); -Uint16Array(buffer [, byteOffset [, length]]);</pre> - -<p>For more information about the constructor syntax and the parameters, see <em><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Syntax">TypedArray</a></em>.</p> - -<h2 id="Properties">Properties</h2> - -<dl> - <dt>{{jsxref("TypedArray.BYTES_PER_ELEMENT", "Uint16Array.BYTES_PER_ELEMENT")}}</dt> - <dd>Returns a number value of the element size. <code>2</code> in the case of an <code>Uint16Array</code>.</dd> - <dt>Uint16Array.length</dt> - <dd>Length property whose value is 3.</dd> - <dt>{{jsxref("TypedArray.name", "Uint16Array.name")}}</dt> - <dd>Returns the string value of the constructor name. In the case of the <code>Uint16Array</code> type: "Uint16Array".</dd> - <dt>{{jsxref("TypedArray.prototype", "Uint16Array.prototype")}}</dt> - <dd>Prototype for the <em>TypedArray</em> objects.</dd> -</dl> - -<h2 id="Methods">Methods</h2> - -<dl> - <dt>{{jsxref("TypedArray.from", "Uint16Array.from()")}}</dt> - <dd>Creates a new <code>Uint16Array</code> from an array-like or iterable object. See also {{jsxref("Array.from()")}}.</dd> - <dt>{{jsxref("TypedArray.of", "Uint16Array.of()")}}</dt> - <dd>Creates a new <code>Uint16Array</code> with a variable number of arguments. See also {{jsxref("Array.of()")}}.</dd> -</dl> - -<h2 id="Boolean_instances" name="Boolean_instances"><code>Uint16Array</code> prototype</h2> - -<p>All <code>Uint16Array</code> objects inherit from {{jsxref("TypedArray.prototype", "%TypedArray%.prototype")}}.</p> - -<h3 id="Properties_2">Properties</h3> - -<dl> - <dt><code>Uint16Array.prototype.constructor</code></dt> - <dd>Returns the function that created an instance's prototype. This is the <code>Uint16Array</code> constructor by default.</dd> - <dt>{{jsxref("TypedArray.prototype.buffer", "Uint16Array.prototype.buffer")}} {{readonlyInline}}</dt> - <dd>Returns the {{jsxref("ArrayBuffer")}} referenced by the <code>Uint16Array</code> Fixed at construction time and thus <strong>read only</strong>.</dd> - <dt>{{jsxref("TypedArray.prototype.byteLength", "Uint16Array.prototype.byteLength")}} {{readonlyInline}}</dt> - <dd>Returns the length (in bytes) of the <code>Uint16Array</code> from the start of its {{jsxref("ArrayBuffer")}}. Fixed at construction time and thus <strong>read only.</strong></dd> - <dt>{{jsxref("TypedArray.prototype.byteOffset", "Uint16Array.prototype.byteOffset")}} {{readonlyInline}}</dt> - <dd>Returns the offset (in bytes) of the <code>Uint16Array</code> from the start of its {{jsxref("ArrayBuffer")}}. Fixed at construction time and thus <strong>read only.</strong></dd> - <dt>{{jsxref("TypedArray.prototype.length", "Uint16Array.prototype.length")}} {{readonlyInline}}</dt> - <dd>Returns the number of elements hold in the <code>Uint16Array</code>. Fixed at construction time and thus <strong>read only.</strong></dd> -</dl> - -<h3 id="Methods_2">Methods</h3> - -<dl> - <dt>{{jsxref("TypedArray.copyWithin", "Uint16Array.prototype.copyWithin()")}}</dt> - <dd>Copies a sequence of array elements within the array. See also {{jsxref("Array.prototype.copyWithin()")}}.</dd> - <dt>{{jsxref("TypedArray.entries", "Uint16Array.prototype.entries()")}}</dt> - <dd>Returns a new <code>Array Iterator</code> object that contains the key/value pairs for each index in the array. See also {{jsxref("Array.prototype.entries()")}}.</dd> - <dt>{{jsxref("TypedArray.every", "Uint16Array.prototype.every()")}}</dt> - <dd>Tests whether all elements in the array pass the test provided by a function. See also {{jsxref("Array.prototype.every()")}}.</dd> - <dt>{{jsxref("TypedArray.fill", "Uint16Array.prototype.fill()")}}</dt> - <dd>Fills all the elements of an array from a start index to an end index with a static value. See also {{jsxref("Array.prototype.fill()")}}.</dd> - <dt>{{jsxref("TypedArray.filter", "Uint16Array.prototype.filter()")}}</dt> - <dd>Creates a new array with all of the elements of this array for which the provided filtering function returns true. See also {{jsxref("Array.prototype.filter()")}}.</dd> - <dt>{{jsxref("TypedArray.find", "Uint16Array.prototype.find()")}}</dt> - <dd>Returns the found value in the array, if an element in the array satisfies the provided testing function or <code>undefined</code> if not found. See also {{jsxref("Array.prototype.find()")}}.</dd> - <dt>{{jsxref("TypedArray.findIndex", "Uint16Array.prototype.findIndex()")}}</dt> - <dd>Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found. See also {{jsxref("Array.prototype.findIndex()")}}.</dd> - <dt>{{jsxref("TypedArray.forEach", "Uint16Array.prototype.forEach()")}}</dt> - <dd>Calls a function for each element in the array. See also {{jsxref("Array.prototype.forEach()")}}.</dd> - <dt>{{jsxref("TypedArray.includes", "Uint16Array.prototype.includes()")}} {{experimental_inline}}</dt> - <dd>Determines whether a typed array includes a certain element, returning <code>true</code> or <code>false</code> as appropriate. See also {{jsxref("Array.prototype.includes()")}}.</dd> - <dt>{{jsxref("TypedArray.indexOf", "Uint16Array.prototype.indexOf()")}}</dt> - <dd>Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found. See also {{jsxref("Array.prototype.indexOf()")}}.</dd> - <dt>{{jsxref("TypedArray.join", "Uint16Array.prototype.join()")}}</dt> - <dd>Joins all elements of an array into a string. See also {{jsxref("Array.prototype.join()")}}.</dd> - <dt>{{jsxref("TypedArray.keys", "Uint16Array.prototype.keys()")}}</dt> - <dd>Returns a new <code>Array Iterator</code> that contains the keys for each index in the array. See also {{jsxref("Array.prototype.keys()")}}.</dd> - <dt>{{jsxref("TypedArray.lastIndexOf", "Uint16Array.prototype.lastIndexOf()")}}</dt> - <dd>Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found. See also {{jsxref("Array.prototype.lastIndexOf()")}}.</dd> - <dt>{{jsxref("TypedArray.map", "Uint16Array.prototype.map()")}}</dt> - <dd>Creates a new array with the results of calling a provided function on every element in this array. See also {{jsxref("Array.prototype.map()")}}.</dd> - <dt>{{jsxref("TypedArray.move", "Uint16Array.prototype.move()")}} {{non-standard_inline}} {{unimplemented_inline}}</dt> - <dd>Former non-standard version of {{jsxref("TypedArray.copyWithin", "Uint16Array.prototype.copyWithin()")}}.</dd> - <dt>{{jsxref("TypedArray.reduce", "Uint16Array.prototype.reduce()")}}</dt> - <dd>Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value. See also {{jsxref("Array.prototype.reduce()")}}.</dd> - <dt>{{jsxref("TypedArray.reduceRight", "Uint16Array.prototype.reduceRight()")}}</dt> - <dd>Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value. See also {{jsxref("Array.prototype.reduceRight()")}}.</dd> - <dt>{{jsxref("TypedArray.reverse", "Uint16Array.prototype.reverse()")}}</dt> - <dd>Reverses the order of the elements of an array — the first becomes the last, and the last becomes the first. See also {{jsxref("Array.prototype.reverse()")}}.</dd> - <dt>{{jsxref("TypedArray.set", "Uint16Array.prototype.set()")}}</dt> - <dd>Stores multiple values in the typed array, reading input values from a specified array.</dd> - <dt>{{jsxref("TypedArray.slice", "Uint16Array.prototype.slice()")}}</dt> - <dd>Extracts a section of an array and returns a new array. See also {{jsxref("Array.prototype.slice()")}}.</dd> - <dt>{{jsxref("TypedArray.some", "Uint16Array.prototype.some()")}}</dt> - <dd>Returns true if at least one element in this array satisfies the provided testing function. See also {{jsxref("Array.prototype.some()")}}.</dd> - <dt>{{jsxref("TypedArray.sort", "Uint16Array.prototype.sort()")}}</dt> - <dd>Sorts the elements of an array in place and returns the array. See also {{jsxref("Array.prototype.sort()")}}.</dd> - <dt>{{jsxref("TypedArray.subarray", "Uint16Array.prototype.subarray()")}}</dt> - <dd>Returns a new <code>Uint16Array</code> from the given start and end element index.</dd> - <dt>{{jsxref("TypedArray.values", "Uint16Array.prototype.values()")}}</dt> - <dd>Returns a new <code>Array Iterator</code> object that contains the values for each index in the array. See also {{jsxref("Array.prototype.values()")}}.</dd> - <dt>{{jsxref("TypedArray.toLocaleString", "Uint16Array.prototype.toLocaleString()")}}</dt> - <dd>Returns a localized string representing the array and its elements. See also {{jsxref("Array.prototype.toLocaleString()")}}.</dd> - <dt>{{jsxref("TypedArray.toString", "Uint16Array.prototype.toString()")}}</dt> - <dd>Returns a string representing the array and its elements. See also {{jsxref("Array.prototype.toString()")}}.</dd> - <dt>{{jsxref("TypedArray.@@iterator", "Uint16Array.prototype[@@iterator]()")}}</dt> - <dd>Returns a new <code>Array Iterator</code> object that contains the values for each index in the array.</dd> -</dl> - -<h2 id="Examples">Examples</h2> - -<pre class="brush: js">// From a length -var uint16 = new Uint16Array(2); -uint16[0] = 42; -console.log(uint16[0]); // 42 -console.log(uint16.length); // 2 -console.log(uint16.BYTES_PER_ELEMENT); // 2 - -// From an array -var arr = new Uint16Array([21,31]); -console.log(arr[1]); // 31 - -// From another TypedArray -var x = new Uint16Array([21, 31]); -var y = new Uint16Array(x); -console.log(y[0]); // 21 - -// From an ArrayBuffer -var buffer = new ArrayBuffer(8); -var z = new Uint16Array(buffer, 0, 4); -</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><a href="https://www.khronos.org/registry/typedarray/specs/latest/#7">Typed Array Specification</a></td> - <td>Obsolete</td> - <td><span><span>Superseded by ECMAScript 6.</span></span></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#table-45', 'TypedArray constructors')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Initial definition in an ECMA standard.</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<p>{{ CompatibilityTable() }}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>7.0</td> - <td>{{ CompatGeckoDesktop("2") }}</td> - <td>10</td> - <td>11.6</td> - <td>5.1</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>4.0</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatGeckoMobile("2") }}</td> - <td>10</td> - <td>11.6</td> - <td>4.2</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Typed_arrays" title="en/JavaScript typed arrays">JavaScript typed arrays</a></li> - <li>{{jsxref("ArrayBuffer")}}</li> - <li>{{jsxref("DataView")}}</li> -</ul> diff --git a/files/pl/web/javascript/reference/operators/instanceof/index.html b/files/pl/web/javascript/reference/operators/instanceof/index.html deleted file mode 100644 index bd98d29e0f..0000000000 --- a/files/pl/web/javascript/reference/operators/instanceof/index.html +++ /dev/null @@ -1,169 +0,0 @@ ---- -title: Operator instanceof -slug: Web/JavaScript/Reference/Operators/instanceof -tags: - - Dokumentacja_JavaScript - - Dokumentacje - - JavaScript - - Strony_wymagające_dopracowania - - Wszystkie_kategorie -translation_of: Web/JavaScript/Reference/Operators/instanceof -original_slug: Web/JavaScript/Referencje/Operatory/Operator_instanceof ---- -<div>{{jsSidebar("Operators")}}</div> - -<p><strong>Operator</strong> <strong><code>instanceof</code> </strong>sprawdza czy właściwość konstruktora <code>prototype</code> pojawia się gdziekolwiek w łańcuchu prototypowym obiektu.</p> - -<p>{{EmbedInteractiveExample("pages/js/expressions-instanceof.html")}}</p> - - - -<h2 id="Składnia">Składnia</h2> - -<pre class="syntaxbox"><em>object</em> instanceof <em>constructor</em></pre> - -<dl> - <dt> - <h3 id="Parametry">Parametry</h3> - <code>object</code></dt> - <dd>Obiekt do testowania.</dd> -</dl> - -<dl> - <dt><code>constructor</code></dt> - <dd>Funkcja przeciwko której testujemy.</dd> -</dl> - -<h2 id="Opis">Opis</h2> - -<p>Operator <code>instanceof</code> sprawdza obecność <code>constructor.prototype</code> w łańcuchu prototypowym obiektu <code>object</code></p> - -<pre class="brush: js">// definiowanie konstruktorów -function C() {} -function D() {} - -var o = new C(); - -// true, ponieważ: Object.getPrototypeOf(o) === C.prototype -o instanceof C; - -// false, ponieważ D.prototype nie występuje w łańcuchu prototypowym o. -o instanceof D; - -o instanceof Object; // true, ponieważ: -C.prototype instanceof Object // true - -C.prototype = {}; -var o2 = new C(); - -o2 instanceof C; // true - -// false, ponieważ C.prototype nie ma już w łańcuchu prototypowym o -o instanceof C; - -D.prototype = new C(); // add C to [[Prototype]] linkage of D -var o3 = new D(); -o3 instanceof D; // true -o3 instanceof C; // true since C.prototype is now in o3's prototype chain -</pre> - -<p>Note that the value of an <code>instanceof</code> test can change based on changes to the <code>prototype</code> property of constructors, and it can also be changed by changing an object prototype using <code>Object.setPrototypeOf</code>. It is also possible using the non-standard <code>__proto__</code> pseudo-property.</p> - -<h3 id="instanceof_and_multiple_context_(e.g._frames_or_windows)"><code>instanceof</code> and multiple context (e.g. frames or windows)</h3> - -<p>Different scopes have different execution environments. This means that they have different built-ins (different global object, different constructors, etc.). This may result in unexpected results. For instance, <code>[] instanceof window.frames[0].Array</code> will return <code>false</code>, because <code>Array.prototype !== </code><code>window.frames[0].Array</code> and arrays inherit from the former.</p> - -<p>This may not make sense at first but when you start dealing with multiple frames or windows in your script and pass objects from one context to another via functions, this will be a valid and strong issue. For instance, you can securely check if a given object is, in fact, an Array using <code>Array.isArray(myObj)</code></p> - -<p>For example checking if a <a href="/en-US/docs/Web/API/Node">Nodes</a> is a <a href="/en-US/docs/Web/API/SVGElement">SVGElement</a> in a different context you can use <code>myNode instanceof myNode.ownerDocument.defaultView.SVGElement</code></p> - -<div class="note"><strong>Note for Mozilla developers:</strong><br> -In code using XPCOM <code>instanceof</code> has special effect: <code>obj instanceof </code><em><code>xpcomInterface</code></em> (e.g. <code>Components.interfaces.nsIFile</code>) calls <code>obj.QueryInterface(<em>xpcomInterface</em>)</code> and returns <code>true</code> if QueryInterface succeeded. A side effect of such call is that you can use <em><code>xpcomInterface</code></em>'s properties on <code>obj</code> after a successful <code>instanceof</code> test. Unlike standard JavaScript globals, the test <code>obj instanceof xpcomInterface</code> works as expected even if <code>obj</code> is from a different scope.</div> - -<h2 id="Examples">Examples</h2> - -<h3 id="Demonstrating_that_String_and_Date_are_of_type_Object_and_exceptional_cases">Demonstrating that <code>String</code> and <code>Date</code> are of type <code>Object</code> and exceptional cases</h3> - -<p>The following code uses <code>instanceof</code> to demonstrate that <code>String</code> and <code>Date</code> objects are also of type <code>Object</code> (they are derived from <code>Object</code>).</p> - -<p>However, objects created with the object literal notation are an exception here: Although the prototype is undefined, <code>instanceof Object</code> returns <code>true</code>.</p> - -<pre class="brush: js">var simpleStr = 'This is a simple string'; -var myString = new String(); -var newStr = new String('String created with constructor'); -var myDate = new Date(); -var myObj = {}; - -simpleStr instanceof String; // returns false, checks the prototype chain, finds undefined -myString instanceof String; // returns true -newStr instanceof String; // returns true -myString instanceof Object; // returns true - -myObj instanceof Object; // returns true, despite an undefined prototype -({}) instanceof Object; // returns true, same case as above - -myString instanceof Date; // returns false - -myDate instanceof Date; // returns true -myDate instanceof Object; // returns true -myDate instanceof String; // returns false -</pre> - -<h3 id="Demonstrating_that_mycar_is_of_type_Car_and_type_Object">Demonstrating that <code>mycar</code> is of type <code>Car</code> and type <code>Object</code></h3> - -<p>The following code creates an object type <code>Car</code> and an instance of that object type, <code>mycar</code>. The <code>instanceof</code> operator demonstrates that the <code>mycar</code> object is of type <code>Car</code> and of type <code>Object</code>.</p> - -<pre class="brush: js">function Car(make, model, year) { - this.make = make; - this.model = model; - this.year = year; -} -var mycar = new Car('Honda', 'Accord', 1998); -var a = mycar instanceof Car; // returns true -var b = mycar instanceof Object; // returns true -</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('ESDraft', '#sec-relational-operators', 'Relational Operators')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-relational-operators', 'Relational Operators')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-11.8.6', 'The instanceof operator')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES3', '#sec-11.8.6', 'The instanceof operator')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Initial definition. Implemented in JavaScript 1.4.</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - - - -<p>{{Compat("javascript.operators.instanceof")}}</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/typeof" title="/en-US/docs/JavaScript/Reference/Operators/typeof">typeof</a></code></li> - <li>{{jsxref("Symbol.hasInstance")}}</li> -</ul> diff --git a/files/pl/web/javascript/reference/operators/this/index.html b/files/pl/web/javascript/reference/operators/this/index.html deleted file mode 100644 index 427d3f843e..0000000000 --- a/files/pl/web/javascript/reference/operators/this/index.html +++ /dev/null @@ -1,347 +0,0 @@ ---- -title: this -slug: Web/JavaScript/Reference/Operators/this -translation_of: Web/JavaScript/Reference/Operators/this -original_slug: Web/JavaScript/Referencje/Operatory/this ---- -<div> -<div>{{jsSidebar("Operators")}}</div> -</div> - -<h2 id="Summary">Summary</h2> - -<p>W JavaScript słówko kluczowe <code>this</code> zachowuje się nieco inaczej w porównaniu do innych języków programowania. Istnieje również kilka różnic między trybem <a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode">strict mode</a> oraz non-strict mode.</p> - -<p>W większości przypadków wartość <code>this</code> jest ustalana na podstawie tego, jak wywołana została dana funkcja. Wartość ta nie może być przypisana podczas wykonywania się funkcji i może być inna za każdym wywołaniem. ES5 wprowadziło metodę <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">bind</a></code> dzięki której <a href="#The_bind_method">możemy przypisać wartość <code>this</code> w funkcji, niezależnie od tego jak została ona wywołana.</a></p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox">this</pre> - -<h2 id="Global_context">Global context</h2> - -<p>In the global execution context (outside of any function), <code>this</code> refers to the global object, whether in strict mode or not.</p> - -<pre class="brush:js">console.log(this.document === document); // true - -// In web browsers, the window object is also the global object: -console.log(this === window); // true - -this.a = 37; -console.log(window.a); // 37 -</pre> - -<h2 id="Function_context">Function context</h2> - -<p>Inside a function, the value of <code>this</code> depends on how the function is called.</p> - -<h3 id="Simple_call">Simple call</h3> - -<pre class="brush:js">function f1(){ - return this; -} - -f1() === window; // global object -</pre> - -<p>In this case, the value of <code>this</code> is not set by the call. Since the code is not in strict mode, the value of <code>this</code> must always be an object so it defaults to the global object.</p> - -<pre class="brush:js">function f2(){ - "use strict"; // see strict mode - return this; -} - -f2() === undefined; -</pre> - -<p>In strict mode, the value of <code>this</code> remains at whatever it's set to when entering the execution context. If it's not defined, it remains undefined. It can also be set to any value, such as <code>null</code> or <code>42</code> or <code>"I am not this"</code>.</p> - -<div class="note"><strong>Note:</strong> In the second example, <code>this</code> should be <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined"><code>undefined</code></a>, because <code>f2</code> was called without providing any base (e.g. <code>window.f2()</code>). This feature wasn't implemented in some browsers when they first started to support <a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode" title="Strict mode">strict mode</a>. As a result, they incorrectly returned the <code>window</code> object.</div> - -<h3 id="As_an_object_method">As an object method</h3> - -<p>When a function is called as a method of an object, its <code>this</code> is set to the object the method is called on.</p> - -<p>In the following example, when <code>o.f()</code> is invoked, inside the function <code>this</code> is bound to the <code>o</code> object.</p> - -<pre class="brush:js">var o = { - prop: 37, - f: function() { - return this.prop; - } -}; - -console.log(o.f()); // logs 37 -</pre> - -<p>Note that this behavior is not at all affected by how or where the function was defined. In the previous example, we defined the function inline as the <code>f</code> member during the definition of <code>o</code>. However, we could have just as easily defined the function first and later attached it to <code>o.f</code>. Doing so results in the same behavior:</p> - -<pre class="brush:js">var o = {prop: 37}; - -function independent() { - return this.prop; -} - -o.f = independent; - -console.log(o.f()); // logs 37 -</pre> - -<p>This demonstrates that it matters only that the function was invoked from the <code>f</code> member of <code>o</code>.</p> - -<p>Similarly, the <code>this</code> binding is only affected by the most immediate member reference. In the following example, when we invoke the function, we call it as a method <code>g</code> of the object <code>o.b</code>. This time during execution, <code>this</code> inside the function will refer to <code>o.b</code>. The fact that the object is itself a member of <code>o</code> has no consequence; the most immediate reference is all that matters.</p> - -<pre class="brush:js">o.b = {g: independent, prop: 42}; -console.log(o.b.g()); // logs 42 -</pre> - -<h4 id="this_on_the_objects_prototype_chain"><code>this</code> on the object's prototype chain</h4> - -<p>The same notion holds true for methods defined somewhere on the object's prototype chain. If the method is on an object's prototype chain, <code>this</code> refers to the object the method was called on, as if the method was on the object.</p> - -<pre class="brush:js">var o = {f:function(){ return this.a + this.b; }}; -var p = Object.create(o); -p.a = 1; -p.b = 4; - -console.log(p.f()); // 5 -</pre> - -<p>In this example, the object assigned to the variable <code>p</code> doesn't have its own <code>f</code> property, it inherits it from its prototype. But it doesn't matter that the lookup for <code>f</code> eventually finds a member with that name on <code>o</code>; the lookup began as a reference to <code>p.f</code>, so <code>this</code> inside the function takes the value of the object referred to as <code>p</code>. That is, since <code>f</code> is called as a method of <code>p</code>, its <code>this</code> refers to <code>p</code>. This is an interesting feature of JavaScript's prototype inheritance.</p> - -<h4 id="this_with_a_getter_or_setter"><code>this</code> with a getter or setter</h4> - -<p>Again, the same notion holds true when a function is invoked from a getter or a setter. A function used as getter or setter has its <code>this</code> bound to the object from which the property is being set or gotten.</p> - -<pre class="brush:js">function modulus(){ - return Math.sqrt(this.re * this.re + this.im * this.im); -} - -var o = { - re: 1, - im: -1, - get phase(){ - return Math.atan2(this.im, this.re); - } -}; - -Object.defineProperty(o, 'modulus', { - get: modulus, enumerable:true, configurable:true}); - -console.log(o.phase, o.modulus); // logs -0.78 1.4142 -</pre> - -<h3 id="As_a_constructor">As a constructor</h3> - -<p>When a function is used as a constructor (with the <code><a href="/en-US/docs/Web/JavaScript/Reference/Operators/new">new</a></code> keyword), its <code>this</code> is bound to new object being constructed.</p> - -<p>Note: while the default for a constructor is to return the object referenced by <code>this</code>, it can instead return some other object (if the return value isn't an object, then the <code>this</code> object is returned).</p> - -<pre class="brush:js">/* - * Constructors work like this: - * - * function MyConstructor(){ - * // Actual function body code goes here. - * // Create properties on |this| as - * // desired by assigning to them. E.g., - * this.fum = "nom"; - * // et cetera... - * - * // If the function has a return statement that - * // returns an object, that object will be the - * // result of the |new| expression. Otherwise, - * // the result of the expression is the object - * // currently bound to |this| - * // (i.e., the common case most usually seen). - * } - */ - -function C(){ - this.a = 37; -} - -var o = new C(); -console.log(o.a); // logs 37 - - -function C2(){ - this.a = 37; - return {a:38}; -} - -o = new C2(); -console.log(o.a); // logs 38 -</pre> - -<p>In the last example (<code>C2</code>), because an object was returned during construction, the new object that <code>this</code> was bound to simply gets discarded. (This essentially makes the statement "<code>this.a = 37;</code>" dead code. It's not exactly dead, because it gets executed, but it can be eliminated with no outside effects.)</p> - -<h3 id="call_and_apply"><code>call</code> and <code>apply</code></h3> - -<p>Where a function uses the <code>this</code> keyword in its body, its value can be bound to a particular object in the call using the <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call">call</a></code> or <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply">apply</a></code> methods that all functions inherit from <code>Function.prototype</code>.</p> - -<pre class="brush:js">function add(c, d){ - return this.a + this.b + c + d; -} - -var o = {a:1, b:3}; - -// The first parameter is the object to use as -// 'this', subsequent parameters are passed as -// arguments in the function call -add.call(o, 5, 7); // 1 + 3 + 5 + 7 = 16 - -// The first parameter is the object to use as -// 'this', the second is an array whose -// members are used as the arguments in the function call -add.apply(o, [10, 20]); // 1 + 3 + 10 + 20 = 34 -</pre> - -<p>Note that with <code>call</code> and <code>apply</code>, if the value passed as <code>this</code> is not an object, an attempt will be made to convert it to an object using the internal <code>ToObject</code> operation. So if the value passed is a primitive like <code>7</code> or <code>'foo'</code>, it will be converted to an Object using the related constructor, so the primitive number <code>7</code> is converted to an object as if by <code>new Number(7)</code> and the string <code>'foo'</code> to an object as if by <code>new String('foo'), e.g.</code></p> - -<pre class="brush:js">function bar() { - console.log(Object.prototype.toString.call(this)); -} - -bar.call(7); // [object Number] -</pre> - -<h3 id="The_bind_method">The <code>bind</code> method</h3> - -<p>ECMAScript 5 introduced <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">Function.prototype.bind</a></code>. Calling <code>f.bind(someObject)</code> creates a new function with the same body and scope as <code>f</code>, but where <code>this</code> occurs in the original function, in the new function it is permanently bound to the first argument of <code>bind</code>, regardless of how the function is being used.</p> - -<pre class="brush:js">function f(){ - return this.a; -} - -var g = f.bind({a:"azerty"}); -console.log(g()); // azerty - -var o = {a:37, f:f, g:g}; -console.log(o.f(), o.g()); // 37, azerty -</pre> - -<h3 id="As_a_DOM_event_handler">As a DOM event handler</h3> - -<p>When a function is used as an event handler, its <code>this</code> is set to the element the event fired from (some browsers do not follow this convention for listeners added dynamically with methods other than <code>addEventListener</code>).</p> - -<pre class="brush:js">// When called as a listener, turns the related element blue -function bluify(e){ - // Always true - console.log(this === e.currentTarget); - // true when currentTarget and target are the same object - console.log(this === e.target); - this.style.backgroundColor = '#A5D9F3'; -} - -// Get a list of every element in the document -var elements = document.getElementsByTagName('*'); - -// Add bluify as a click listener so when the -// element is clicked on, it turns blue -for(var i=0 ; i<elements.length ; i++){ - elements[i].addEventListener('click', bluify, false); -}</pre> - -<h3 id="In_an_in–line_event_handler">In an in–line event handler</h3> - -<p>When code is called from an in–line handler, its <code>this</code> is set to the DOM element on which the listener is placed:</p> - -<pre class="brush:js"><button onclick="alert(this.tagName.toLowerCase());"> - Show this -</button> -</pre> - -<p>The above alert shows <code>button</code>. Note however that only the outer code has its <code>this</code> set this way:</p> - -<pre class="brush:js"><button onclick="alert((function(){return this}()));"> - Show inner this -</button> -</pre> - -<p>In this case, the inner function's <code>this</code> isn't set so it returns the global/window object (i.e. the default object in non–strict mode where <code>this</code> isn't set by the call).</p> - -<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>ECMAScript 1st Edition.</td> - <td>Standard</td> - <td>Initial definition. Implemented in JavaScript 1.0</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-11.1.1', 'The this keyword')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-this-keyword', 'The this keyword')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<p>{{ CompatibilityTable() }}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - <td>{{ CompatVersionUnknown() }}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also" name="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode">Strict mode</a></li> - <li><a href="http://bjorn.tipling.com/all-this">All this</a>, an article about <code>this</code> in different contexts</li> -</ul> diff --git a/files/pl/web/javascript/reference/statements/throw/index.html b/files/pl/web/javascript/reference/statements/throw/index.html deleted file mode 100644 index d47ab9803b..0000000000 --- a/files/pl/web/javascript/reference/statements/throw/index.html +++ /dev/null @@ -1,198 +0,0 @@ ---- -title: throw -slug: Web/JavaScript/Reference/Statements/throw -tags: - - Dokumentacja_JavaScript - - Dokumentacje - - JavaScript - - Strony_wymagające_dopracowania - - Wszystkie_kategorie -translation_of: Web/JavaScript/Reference/Statements/throw -original_slug: Web/JavaScript/Referencje/Polecenia/throw ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>The <strong><code>throw</code> statement</strong> throws a user-defined exception. Execution of the current function will stop (the statements after <code>throw</code> won't be executed), and control will be passed to the first <a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch"><code>catch</code></a> block in the call stack. If no <code>catch</code> block exists among caller functions, the program will terminate.</p> - -<div>{{EmbedInteractiveExample("pages/js/statement-throw.html")}}</div> - - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox">throw <em>expression</em>; </pre> - -<dl> - <dt><code>expression</code></dt> - <dd>The expression to throw.</dd> -</dl> - -<h2 id="Description">Description</h2> - -<p>Use the <code>throw</code> statement to throw an exception. When you throw an exception, <code>expression</code> specifies the value of the exception. Each of the following throws an exception:</p> - -<pre class="brush: js">throw 'Error2'; // generates an exception with a string value -throw 42; // generates an exception with the value 42 -throw true; // generates an exception with the value true</pre> - -<p>Also note that the <code>throw</code> statement is affected by <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion">automatic semicolon insertion (ASI)</a> as no line terminator between the <code>throw</code> keyword and the expression is allowed.</p> - -<h2 id="Examples">Examples</h2> - -<h3 id="Throw_an_object">Throw an object</h3> - -<p>You can specify an object when you throw an exception. You can then reference the object's properties in the <code>catch</code> block. The following example creates an object of type <code>UserException</code> and uses it in a <code>throw</code> statement.</p> - -<pre class="brush: js">function UserException(message) { - this.message = message; - this.name = 'UserException'; -} -function getMonthName(mo) { - mo = mo - 1; // Adjust month number for array index (1 = Jan, 12 = Dec) - var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', - 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - if (months[mo] !== undefined) { - return months[mo]; - } else { - throw new UserException('InvalidMonthNo'); - } -} - -try { - // statements to try - var myMonth = 15; // 15 is out of bound to raise the exception - var monthName = getMonthName(myMonth); -} catch (e) { - monthName = 'unknown'; - console.log(e.message, e.name); // pass exception object to err handler -} -</pre> - -<h3 id="Another_example_of_throwing_an_object">Another example of throwing an object</h3> - -<p>The following example tests an input string for a U.S. zip code. If the zip code uses an invalid format, the throw statement throws an exception by creating an object of type <code>ZipCodeFormatException</code>.</p> - -<pre class="brush: js">/* - * Creates a ZipCode object. - * - * Accepted formats for a zip code are: - * 12345 - * 12345-6789 - * 123456789 - * 12345 6789 - * - * If the argument passed to the ZipCode constructor does not - * conform to one of these patterns, an exception is thrown. - */ - -function ZipCode(zip) { - zip = new String(zip); - pattern = /[0-9]{5}([- ]?[0-9]{4})?/; - if (pattern.test(zip)) { - // zip code value will be the first match in the string - this.value = zip.match(pattern)[0]; - this.valueOf = function() { - return this.value - }; - this.toString = function() { - return String(this.value) - }; - } else { - throw new ZipCodeFormatException(zip); - } -} - -function ZipCodeFormatException(value) { - this.value = value; - this.message = 'does not conform to the expected format for a zip code'; - this.toString = function() { - return this.value + this.message; - }; -} - -/* - * This could be in a script that validates address data - * for US addresses. - */ - -const ZIPCODE_INVALID = -1; -const ZIPCODE_UNKNOWN_ERROR = -2; - -function verifyZipCode(z) { - try { - z = new ZipCode(z); - } catch (e) { - if (e instanceof ZipCodeFormatException) { - return ZIPCODE_INVALID; - } else { - return ZIPCODE_UNKNOWN_ERROR; - } - } - return z; -} - -a = verifyZipCode(95060); // returns 95060 -b = verifyZipCode(9560); // returns -1 -c = verifyZipCode('a'); // returns -1 -d = verifyZipCode('95060'); // returns 95060 -e = verifyZipCode('95060 1234'); // returns 95060 1234 -</pre> - -<h3 id="Rethrow_an_exception">Rethrow an exception</h3> - -<p>You can use <code>throw</code> to rethrow an exception after you catch it. The following example catches an exception with a numeric value and rethrows it if the value is over 50. The rethrown exception propagates up to the enclosing function or to the top level so that the user sees it.</p> - -<pre class="brush: js">try { - throw n; // throws an exception with a numeric value -} catch (e) { - if (e <= 50) { - // statements to handle exceptions 1-50 - } else { - // cannot handle this exception, so rethrow - throw e; - } -} -</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('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Initial definition. Implemented in JavaScript 1.4</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-12.13', 'throw statement')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-throw-statement', 'throw statement')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-throw-statement', 'throw statement')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - - - -<p>{{Compat("javascript.statements.throw")}}</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch"><code>try...catch</code></a></li> -</ul> |