diff options
author | Ryan Johnson <rjohnson@mozilla.com> | 2021-04-29 16:16:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-29 16:16:42 -0700 |
commit | 95aca4b4d8fa62815d4bd412fff1a364f842814a (patch) | |
tree | 5e57661720fe9058d5c7db637e764800b50f9060 /files/nl/web/javascript/reference/global_objects | |
parent | ee3b1c87e3c8e72ca130943eed260ad642246581 (diff) | |
download | translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2 translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip |
remove retired locales (#699)
Diffstat (limited to 'files/nl/web/javascript/reference/global_objects')
32 files changed, 0 insertions, 6490 deletions
diff --git a/files/nl/web/javascript/reference/global_objects/array/concat/index.html b/files/nl/web/javascript/reference/global_objects/array/concat/index.html deleted file mode 100644 index b224c3fe3d..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/concat/index.html +++ /dev/null @@ -1,176 +0,0 @@ ---- -title: Array.prototype.concat() -slug: Web/JavaScript/Reference/Global_Objects/Array/concat -tags: - - Array - - JavaScript - - Methode(2) - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Array/concat ---- -<div>{{JSRef}}</div> - -<p><code>De <strong>concat()</strong></code> methode geeft een nieuwe array terug bestaande uit de array waarop het is aangeroepen samengevoegd met de array(s) en/of waarden die zijn geleverd als argumenten.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>var <var>nieuwe_array</var> = <var>oude_array</var>.concat(waarde1[, waarde2[, ...[, waardeN]]])</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>waardeN</code></dt> - <dd>Arrays en/of waarden om te concateneren in een nieuwe array. Zie de beschrijving voor details.</dd> -</dl> - -<h3 id="Returnwaarde">Returnwaarde</h3> - -<p>Een nieuwe instantie van type {{jsxref("Array")}}.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p><code>concat</code> maakt een nieuwe array bestaande uit de elementen in het object waarop het is aangeroepen, gevolgd door voor ieder argument de elementen van dat argument (als het argument een array is) of het argument zelf (als het argument geen array is).</p> - -<p><code>concat</code> verandert <code>this</code> niet en ook niet de als argument gegeven arrays, maar levert in plaats daarvan een <em>shallow copy</em> welke kopieën bevat van dezelfde elementen gecombineerd van de orginele arrays. Elementen van de orginele arrays worden als volgt gekopiëerd in de nieuwe array:</p> - -<ul> - <li>Objectreferenties (en niet het daardwerkelijke object): <code>concat</code> kopieert objectreferenties in de nieuwe array. Zowel de orginele array als de nieuwe array verwijzen naar dezelfde objecten. Dit betekent, als een verwezen object gewijzigd wordt, de wijzigingen zichtbaar zijn in zowel de nieuwe als de orginele array.</li> - <li>Strings en getallen (niet {{jsxref("Global_Objects/String", "String")}} en {{jsxref("Global_Objects/Number", "Number")}} objects): <code>concat</code> kopieert de waarden van strings en getallen in de nieuwe array.</li> -</ul> - -<div class="note"> -<p><strong>Opmerking:</strong> Concateneren van array(s)/waarde(n) laat de orginelen onaangetast. Bovendien zal iedere operatie op de nieuwe array geen effect hebben op de orginele array en vice versa.</p> -</div> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Concateneren_van_twee_arrays">Concateneren van twee arrays</h3> - -<p>De volgende code concateneert twee arrays</p> - -<pre class="brush: js">var alfa = ['a', 'b', 'c'], - nummer = [1, 2, 3]; - -var alfaNummeriek = alfa.concat( nummer ); - -console.log(alfaNummeriek); // Resultaat: ['a', 'b', 'c', 1, 2, 3] -</pre> - -<h3 id="Concateneren_van_drie_arrays">Concateneren van drie arrays</h3> - -<p>De volgende code concateneert drie arrays</p> - -<pre class="brush: js">var num1 = [1, 2, 3], - num2 = [4, 5, 6], - num3 = [7, 8, 9]; - -var nums = num1.concat(num2, num3); - -console.log(nums); // Resultaat: [1, 2, 3, 4, 5, 6, 7, 8, 9] -</pre> - -<h3 id="Concateneren_van_waarden_naar_een_array">Concateneren van waarden naar een array</h3> - -<p>De volgende code concateneert drie waarden naar een array:</p> - -<pre class="brush: js">var alfa = ['a', 'b', 'c']; - -var alfaNumeriek = alfa.concat(1, [2, 3]); - -console.log( alfaNumeriek); -// Resultaat: ['a', 'b', 'c', 1, 2, 3] -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Eerste definitie. Geïmplementeerd in JavaScript 1.2.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.4', 'Array.prototype.concat')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.concat', 'Array.prototype.concat')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.concat', 'Array.prototype.concat')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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>Basis support</td> - <td>{{CompatChrome("1.0")}}</td> - <td>{{CompatGeckoDesktop("1.7")}}</td> - <td>{{CompatIE("5.5")}}</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>Basis 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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.push", "push")}} / {{jsxref("Array.pop", "pop")}} — toevoegen/verwijderen van elementen aan het einde van de array</li> - <li>{{jsxref("Array.unshift", "unshift")}} / {{jsxref("Array.shift", "shift")}} — toevoegen/verwijderen van elementen aan het begin van de array</li> - <li>{{jsxref("Array.splice", "splice")}} — toevoegen/verwijderen van elementen op een gespecificeerde locatie van de array</li> - <li>{{jsxref("String.prototype.concat()")}}</li> - <li>{{jsxref("Symbol.isConcatSpreadable")}} – control flattening.</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/entries/index.html b/files/nl/web/javascript/reference/global_objects/array/entries/index.html deleted file mode 100644 index add0b7439a..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/entries/index.html +++ /dev/null @@ -1,132 +0,0 @@ ---- -title: Array.prototype.entries() -slug: Web/JavaScript/Reference/Global_Objects/Array/entries -tags: - - Array - - ECMAScript 2015 - - Iterator - - JavaScript - - Méthode - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Array/entries ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>entries()</strong></code> funtie geeft een nieuw <code><strong>Array Iterator</strong></code> object dat de key/value paren bevat voor elk onderdeel van de array.</p> - -<pre class="brush:js">var a = ['a', 'b', 'c']; -var iterator = a.entries(); - -console.log(iterator.next().value); // [0, 'a'] -console.log(iterator.next().value); // [1, 'b'] -console.log(iterator.next().value); // [2, 'c'] -</pre> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>a</var>.entries()</pre> - -<h3 id="Return_waarde">Return waarde</h3> - -<p>Een nieuw {{jsxref("Array")}} iterator object.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="De_for…of_loop">De <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for…of</a> loop</h3> - -<pre class="brush:js">var a = ['a', 'b', 'c']; -var iterator = a.entries(); - -for (let e of iterator) { - console.log(e); -} -// [0, 'a'] -// [1, 'b'] -// [2, 'c'] -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerkingen</th> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.entries', 'Array.prototype.entries')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Standaard definitie.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.entries', 'Array.prototype.entries')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Functie</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basis ondersteuning</td> - <td>{{CompatChrome("38")}}</td> - <td>{{CompatGeckoDesktop("28")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatOpera("25")}}</td> - <td>{{CompatSafari("7.1")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Functie</th> - <th>Android</th> - <th>Chrome voor Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basis ondersteuning</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatGeckoMobile("28")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>8.0</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.keys()")}}</li> - <li>{{jsxref("Array.prototype.values()")}}</li> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li>{{jsxref("Array.prototype.every()")}}</li> - <li>{{jsxref("Array.prototype.some()")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for...of</a></li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">Iteration protocols</a></li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/every/index.html b/files/nl/web/javascript/reference/global_objects/array/every/index.html deleted file mode 100644 index 36834fec57..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/every/index.html +++ /dev/null @@ -1,191 +0,0 @@ ---- -title: Array.prototype.every() -slug: Web/JavaScript/Reference/Global_Objects/Array/every -tags: - - Array - - ECMAScript 5 - - JavaScript - - Méthode - - Prototype - - polyfill -translation_of: Web/JavaScript/Reference/Global_Objects/Array/every ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>every()</strong></code> methode controleert of alle elementen in de array slagen voor de test die opgelegd wordt in de opgegeven functie.</p> - -<div>{{EmbedInteractiveExample("pages/js/array-every.html")}}</div> - -<p class="hidden">De broncode van dit interactieve voorbeeld wordt bewaard in een GitHub repository. Als je wilt bijdragen aan het interactieve voorbeelden project, clone dan <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> en stuur ons een pull request pull request.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>arr</var>.every(<var>callback</var>[, <var>thisArg</var>])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>Functie die elk element checkt, gebruikt 3 argumenten: - <dl> - <dt><code>currentValue</code> (verplicht)</dt> - <dd>Het huidige element wat wordt verwerkt in het array.</dd> - <dt><code>index</code> (optioneel)</dt> - <dd>De index van het huidige element wat wordt verwerkt in het array.</dd> - <dt><code>array</code> (optioneel)</dt> - <dd>Het array waarop de methode <code>every</code> werd aangeroepen.</dd> - </dl> - </dd> - <dt><code>thisArg</code></dt> - <dd>Optioneel. Deze waarde wordt gebruikt als <code>this</code> wanneer <code>callback</code> wordt uitgevoerd.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p><code><strong>true</strong></code> als de callback functie een {{Glossary("truthy")}} waarde terug geeft voor elk element uit het array; anders, <code><strong>false</strong></code>.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De <code>every</code> methode voert voor elk element in het array de <code>callback</code> functie uit tot een element een {{Glossary("falsy")}} waarde teruggeeft. Wanneer een element met deze waarde gevonden wordt, geeft de <code>every</code> methode gelijk <code>false</code> terug. Als <code>callback</code> een {{Glossary("truthy")}} terug geeft voor alle elementen in het array zal <code>every</code> <code>true</code> terug geven. <code>callback</code> wordt alleen aangeroepen voor elementen in het array met een waarde; het wordt niet aangeroepen voor elementen die zijn gedeleted of nooit een waarde hebben gekregen.</p> - -<p><code>callback</code> wordt aangeroepen met 3 argumenten: de waarde van het element, de index van het element, en het Array object dat wordt doorlopen.</p> - -<p>Wanneer een <code>thisArg</code> parameter wordt meegegeven aan <code>every</code> zal dit gebruikt worden als de <code>this</code> waarde van de <code>callback</code>. Indien dit niet wordt meegeven wordt <code>undefined</code> gebruikt als <code>this</code> waarde. De voor de callback uiteindelijk gebruikte this waarde wordt bepaald volgens <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">de normale regels om this te bepalen voor een functie</a>.</p> - -<p><code>every</code> verandert het array waarop het wordt aangeroepen niet.</p> - -<p>De set van elementen die verwerkt zal worden door <code>every</code> wordt bepaald voor de eerste aanroep van <code>callback</code>. Elementen die na het aanroepen van <code>every</code> worden toegevoegd aan het array zullen niet door <code>callback</code> worden bezocht. Als bestaande elementen in het array worden gewijzigd zal de waarde die naar de <code>callback</code> gestuurd wordt de waarde zijn zoals deze was toen <code>every</code> aangeroepen werd; verwijderde elementen worden niet bezocht door <code>callback</code>.</p> - -<p><code>every</code> werkt als een "voor alle" kwantor in de wiskunde en de logica. In het bijzonder voor een lege array, hier wordt <code>true</code> terug gegeven. (Het is "<a href="http://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics">vacuously true</a>" dat alle element van een <a href="https://nl.wikipedia.org/wiki/Lege_verzameling">lege set</a> voldoen aan welke gegeven conditie dan ook.)</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Test_grootte_van_alle_array_elementen">Test grootte van alle array elementen</h3> - -<p>Het volgende voorbeeld checkt of alle elementen in het array groter zijn dan 10.</p> - -<pre class="brush: js">function isBigEnough(element, index, array) { - return element >= 10; -} -[12, 5, 8, 130, 44].every(isBigEnough); // false -[12, 54, 18, 130, 44].every(isBigEnough); // true -</pre> - -<h3 id="Met_arrow_functies">Met arrow functies</h3> - -<p><a href="/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow functions</a> geven een kortere syntax voor dezelfde check.</p> - -<pre class="brush: js">[12, 5, 8, 130, 44].every(x => x >= 10); // false -[12, 54, 18, 130, 44].every(x => x >= 10); // true</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p><code>every</code> is vanaf de 5e editie toegevoegd aan de ECMA-262 standaard; hierdoor is het mogelijk niet aanwezig in andere implementies van de standaard. Je kunt hier omheen werken door de volgende code toe te voegen aan je script. Hiermee geef je <code>every</code> de mogelijkheid om gebruikt te worden in implementaties die dat in beginsel niet ondersteunen. Dit algoritme is gelijk aan het algoritme in ECMS-262, 5e editie. Hierbij moet er van uit gegaan worden dat <code>Object</code> en <code>TypeError</code> hun originele waarde hebben en dat <code>callbackfn.call</code> de originele waarde van {{jsxref("Function.prototype.call")}} checkt.</p> - -<pre class="brush: js">if (!Array.prototype.every) { - Array.prototype.every = function(callbackfn, thisArg) { - 'use strict'; - var T, k; - - if (this == null) { - throw new TypeError('this is null or not defined'); - } - - // 1. Let O be the result of calling ToObject passing the this - // value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get internal method - // of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = O.length >>> 0; - - // 4. If IsCallable(callbackfn) is false, throw a TypeError exception. - if (typeof callbackfn !== 'function') { - throw new TypeError(); - } - - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - if (arguments.length > 1) { - T = thisArg; - } - - // 6. Let k be 0. - k = 0; - - // 7. Repeat, while k < len - while (k < len) { - - var kValue; - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal - // method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal method - // of O with argument Pk. - kValue = O[k]; - - // ii. Let testResult be the result of calling the Call internal method - // of callbackfn with T as the this value and argument list - // containing kValue, k, and O. - var testResult = callbackfn.call(T, kValue, k, O); - - // iii. If ToBoolean(testResult) is false, return false. - if (!testResult) { - return false; - } - } - k++; - } - return true; - }; -} -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.16', 'Array.prototype.every')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Initiele definitie. Geimplementeerd in JavaScript 1.6.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.every', 'Array.prototype.every')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.every', 'Array.prototype.every')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div> -<div class="hidden">De compatibility tabel op deze pagina is gegenereerd van gestructureerde data. Als je wilt bijdragen aan deze data, If you'd like to contribute to the data, clone dan <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> en stuur ons een pull request.</div> - -<p>{{Compat("javascript.builtins.Array.every")}}</p> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li>{{jsxref("Array.prototype.some()")}}</li> - <li>{{jsxref("TypedArray.prototype.every()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/fill/index.html b/files/nl/web/javascript/reference/global_objects/array/fill/index.html deleted file mode 100644 index 205f12011a..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/fill/index.html +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: Array.prototype.fill() -slug: Web/JavaScript/Reference/Global_Objects/Array/fill -tags: - - Functies -translation_of: Web/JavaScript/Reference/Global_Objects/Array/fill ---- -<div>{{JSRef}}</div> - -<p><span class="seoSummary">De <code><strong>fill()</strong></code> functie verandert alle elementen in een array naar statische waarde. Vanaf de eerste index (standaard <code>0</code>) tot de laatste index (standaard <code>array.length</code>). De functie geeft de aangepaste array terug.</span></p> - -<div>{{EmbedInteractiveExample("pages/js/array-fill.html")}}</div> - -<p class="hidden">De bron van dit interactieve voorbeeld is opgeslagen in een GitHub repository. Als u wilt bijdragen aan het interactieve voorbeelden project, clone dan graag <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> en stuur ons een pull verzoek.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox notranslate"><var>arr</var>.fill(<var>value[</var>, <var>start[<var>, <var>end]]</var>)</var></var> -</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>value</code></dt> - <dd>Waarde om de array mee te vullen. (Let op, alle elementen in de array krijgen exact deze waarde.)</dd> - <dt><code>start</code> {{optional_inline}}</dt> - <dd>Start index, standaard <code>0</code>.</dd> - <dt><code>end</code> {{optional_inline}}</dt> - <dd>Laatste index, standaard <code>arr.length</code>.</dd> -</dl> - -<h3 id="Return_waarde">Return waarde</h3> - -<p>De aangepaste array, gevuld met <code>value</code>.</p> - -<h2 id="Description">Description</h2> - -<ul> - <li>Als <code>start</code> negatief is, dan wordt het uitgevoerd als <code>array.length + start</code>.</li> - <li>Als <code>end</code> negatief is, dan wordt het uitgevoerd als <code>array.length + end</code>.</li> - <li><code>fill</code> is bedoeld als generiek: de <code>this</code> waarde hoeft geen <code>Array</code> object te zijn.</li> - <li><code>fill</code> is een muterende functie: het verandert de array zelf een geeft deze array terug, niet een kopie ervan.</li> - <li>Als de eerste parameter een object is, dan zal iedere positie in de array hieraan refereren.</li> -</ul> - -<h2 id="Polyfill">Polyfill</h2> - -<pre class="brush: js notranslate">if (!Array.prototype.fill) { - Object.defineProperty(Array.prototype, 'fill', { - value: function(value) { - - // Steps 1-2. - if (this == null) { - throw new TypeError('this is null or not defined'); - } - - var O = Object(this); - - // Steps 3-5. - var len = O.length >>> 0; - - // Steps 6-7. - var start = arguments[1]; - var relativeStart = start >> 0; - - // Step 8. - var k = relativeStart < 0 ? - Math.max(len + relativeStart, 0) : - Math.min(relativeStart, len); - - // Steps 9-10. - var end = arguments[2]; - var relativeEnd = end === undefined ? - len : end >> 0; - - // Step 11. - var finalValue = relativeEnd < 0 ? - Math.max(len + relativeEnd, 0) : - Math.min(relativeEnd, len); - - // Step 12. - while (k < finalValue) { - O[k] = value; - k++; - } - - // Step 13. - return O; - } - }); -} -</pre> - -<p>Als verouderde JavaScript engines ondersteund moeten worden, welke <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a> </code> niet ondersteunen, dan is het beter om helemaal geen polyfill <code>Array.prototype</code> functies te gebruiken, aangezien ze dan niet non-enumerable te maken zijn.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Fill_toepassen">Fill toepassen</h3> - -<pre class="brush: js notranslate">[1, 2, 3].fill(4) // [4, 4, 4] -[1, 2, 3].fill(4, 1) // [1, 4, 4] -[1, 2, 3].fill(4, 1, 2) // [1, 4, 3] -[1, 2, 3].fill(4, 1, 1) // [1, 2, 3] -[1, 2, 3].fill(4, 3, 3) // [1, 2, 3] -[1, 2, 3].fill(4, -3, -2) // [4, 2, 3] -[1, 2, 3].fill(4, NaN, NaN) // [1, 2, 3] -[1, 2, 3].fill(4, 3, 5) // [1, 2, 3] -Array(3).fill(4) // [4, 4, 4] -[].fill.call({ length: 3 }, 4) // {0: 4, 1: 4, 2: 4, length: 3} - -// Een enkel object, waaraan door iedere positie in de array gerefereerd wordt: -let arr = Array(3).fill({}) // [{}, {}, {}] -arr[0].hi = "hi" // [{ hi: "hi" }, { hi: "hi" }, { hi: "hi" }] -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.fill', 'Array.prototype.fill')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</h2> - -<div> -<div class="hidden">De compatibiliteits-tabel op deze pagina is gegenereerd fuit gestructureerde data. Als u wilt bijdragen aan de data, kijk dan op <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> en stuur ons een pull verzoek.</div> - -<p>{{Compat("javascript.builtins.Array.fill")}}</p> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array")}}</li> - <li>{{jsxref("TypedArray.prototype.fill()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/filter/index.html b/files/nl/web/javascript/reference/global_objects/array/filter/index.html deleted file mode 100644 index 433300acaa..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/filter/index.html +++ /dev/null @@ -1,217 +0,0 @@ ---- -title: Array.prototype.filter() -slug: Web/JavaScript/Reference/Global_Objects/Array/filter -translation_of: Web/JavaScript/Reference/Global_Objects/Array/filter ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>filter()</strong></code> method maakt een nieuwe array aan met enkel die elementen die de test doorstaan van een functie naar keuze.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>var new_array = arr</var>.filter(<var>callback</var>[, <var>thisArg</var>])</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>Functie, onderwerpt ieder element aan een test. Wordt aangeroepen met argumenten <code>(element, index, array)</code>. Levert als resultaat de waarde <code>true</code> om het element te behouden, of anders <code>false</code>.</dd> - <dt><code>thisArg</code></dt> - <dd>Optioneel. Te gebruiken als de <code>this</code> waarde, wanneer een <code>callback</code> wordt uitgevoerd.</dd> -</dl> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p><code>filter()</code> roept een geleverde <code>callback</code> functie één keer aan voor ieder element van een array en maakt een nieuwe array aan met alle waarden waarvoor de <code>callback</code> <a href="/en-US/docs/Glossary/Truthy">een waarde welke kan worden omgezet naar <code>true (truthy values)</code></a> retourneert. <code>callback</code> wordt alleen aangeroepen voor indices van de array, welke een waarde bezitten; deze wordt niet gebruikt voor indices welke zijn verwijderd, of welke nooit een waarde hebben verkregen. Array elements die niet de <code>callback</code> test doorstaan, worden simpelweg overgeslagen en worden niet in de nieuwe array opgenomen.</p> - -<p><code>callback</code> wordt aangeroepen met drie argumenten:</p> - -<ol> - <li>de waarde (value) van het element</li> - <li>de index van het element</li> - <li>het Array object dat wordt veranderd</li> -</ol> - -<p>Wanneer een <code>thisArg</code> parameter wordt toegevoegd aan <code>filter</code>, zal deze worden doorgegeven aan <code>callback</code> wanneer deze wordt aangeroepen, om gebruikt te worden als <code>this</code> waarde. In het andere geval zal de waarde <code>undefined</code> worden gebruikt als <code>this</code> waarde. De <code>this</code> waarde, uiteindelijk zichtbaar in <code>callback</code> wordt bepaald door <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">de gebruikelijke regels om de <code>this</code> waarde te bepalen voor een functie</a>.</p> - -<p><code>filter()</code> verandert de array zelf niet, van waaruit deze als method wordt aangeroepen.</p> - -<p>De reeks (range) van elementen welke door <code>filter()</code> onderhanden wordt genomen, wordt al voor de eerste aanroep van <code>callback</code> bepaald. Elementen, die aan de originele array worden toegevoegd nadat de <code>filter()</code> method was aangeroepen, zullen niet worden onderworpen aan <code>callback</code>. Indien bestaande elementen worden gewijzigd, of verwijderd, dan zal hun waarde, zoals overgedragen aan <code>callback</code>, de waarde zijn als die is, op het moment dat <code>filter()</code> ze bezoekt; elementen die worden verwijderd worden ook niet in behandeling genomen.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Filter_lage_waarden">Filter lage waarden</h3> - -<p>Het volgende voorbeeld gebruikt <code>filter()</code> om een gefilterde array aan te maken, waarbij alle waarden onder de 10 zijn verwijderd.</p> - -<pre class="brush: js">function isBigEnough(value) { - return value >= 10; -} -var filtered = [12, 5, 8, 130, 44].filter(isBigEnough); -// filtered is [12, 130, 44] -</pre> - -<h3 id="Filter_foutieve_items_van_JSON">Filter foutieve items van JSON</h3> - -<p>Het volgende voorbeeld gebruikten <code>filter()</code> voor een gefilterde json van alle elementen met een numerieke <code>id</code>.</p> - -<pre class="brush: js">var arr = [ - { id: 15 }, - { id: -1 }, - { id: 0 }, - { id: 3 }, - { id: 12.2 }, - { }, - { id: null }, - { id: NaN }, - { id: 'undefined' } -]; - -var invalidEntries = 0; - -function filterByID(obj) { - if ('id' in obj && typeof(obj.id) === 'number' && !isNaN(obj.id)) { - return true; - } else { - invalidEntries++; - return false; - } -} - -var arrByID = arr.filter(filterByID); - -console.log('Gefilterde Array\n', arrByID); -// Gefilterde Array -// [{ id: 15 }, { id: -1 }, { id: 0 }, { id: 3 }, { id: 12.2 }] - -console.log('Number of Invalid Entries = ', invalidEntries); -// Number of Invalid Entries = 4 -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p><code>filter()</code> werd toegevoegd aan de ECMA-262 standaard in de 5de editie; als deze kan het zijn dat deze niet in alle toepassingen van de standaard voorkomt. Als alternatief kun je de volgende code aan het begin van je scripts zetten, waardoor het gebruik van <code>filter()</code> word toegestaan binnen ECMA-262 implementaties, die dit nog niet van nature ondersteunen. Het algoritme is precies die, zoals gespecificeerd in ECMA-262, 5de editie, aangenomen dat <code>fn.call</code> resulteert in de beginwaarde van {{jsxref("Function.prototype.call()")}}, en dat {{jsxref("Array.prototype.push()")}} nog zijn originele waarde heeft.</p> - -<pre class="brush: js">if (!Array.prototype.filter) { - Array.prototype.filter = function(fun/*, thisArg*/) { - 'use strict'; - - if (this === void 0 || this === null) { - throw new TypeError(); - } - - var t = Object(this); - var len = t.length >>> 0; - if (typeof fun !== 'function') { - throw new TypeError(); - } - - var res = []; - var thisArg = arguments.length >= 2 ? arguments[1] : void 0; - for (var i = 0; i < len; i++) { - if (i in t) { - var val = t[i]; - - // NOTE: Technically this should Object.defineProperty at - // the next index, as push can be affected by - // properties on Object.prototype and Array.prototype. - // But that method's new, and collisions should be - // rare, so use the more-compatible alternative. - if (fun.call(thisArg, val, i, t)) { - res.push(val); - } - } - } - - return res; - }; -} -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Commentaar</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.20', 'Array.prototype.filter')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Initiele definitie. Geimplementeerd in JavaScript 1.6.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.filter', 'Array.prototype.filter')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.filter', 'Array.prototype.filter')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Eigenschap</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>{{CompatGeckoDesktop("1.8")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Eigenschap</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>{{CompatGeckoMobile("1.8")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li>{{jsxref("Array.prototype.every()")}}</li> - <li>{{jsxref("Array.prototype.some()")}}</li> - <li>{{jsxref("Array.prototype.reduce()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/find/index.html b/files/nl/web/javascript/reference/global_objects/array/find/index.html deleted file mode 100644 index 2d9443ef47..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/find/index.html +++ /dev/null @@ -1,224 +0,0 @@ ---- -title: Array.prototype.find() -slug: Web/JavaScript/Reference/Global_Objects/Array/find -tags: - - Array - - ECMAScript 2015 - - ECMAScript6 - - JavaScript - - Method - - Prototype - - polyfill -translation_of: Web/JavaScript/Reference/Global_Objects/Array/find ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>find()</strong></code>-methode geeft de <strong>waarde</strong> van het <strong>eerste array element </strong>dat aan de testfunctie voldoet terug. Als geen van de elementen uit het array aan de testfunctie voldoen, dan wordt {{jsxref("undefined")}} teruggegeven.</p> - -<p>Zie ook de {{jsxref("Array.findIndex", "findIndex()")}}-methode, die de <strong>index</strong> van het gevonden element in de array teruggeeft in plaats van de waarde zelf.</p> - -<h2 id="Syntaxis">Syntaxis</h2> - -<pre class="syntaxbox"><code><var>arr</var>.find(<var>callback</var>[, <var>thisArg</var>])</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>Functie om voor alle waarden in de array uit te voeren, die drie argumenten accepteert: - <dl> - <dt><code>element</code></dt> - <dd>Het huidige element uit de array dat wordt verwerkt.</dd> - <dt><code>index</code></dt> - <dd>De index van het huidige element uit de array dat wordt verwerkt.</dd> - <dt><code>array</code></dt> - <dd>De array waarop <code>find</code> werd aangeroepen.</dd> - </dl> - </dd> - <dt><code>thisArg</code></dt> - <dd>Optioneel. Object om voor <code>this</code> te gebruiken tijdens het uitvoeren van <code>callback</code>.</dd> -</dl> - -<h3 id="Retourwaarde">Retourwaarde</h3> - -<p>Een waarde in de array als een element aan de testfunctie voldoet, anders {{jsxref("undefined")}}.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De <code>find</code>-methode voert de <code>callback</code>-functie eenmaal per aanwezig element in de array uit, totdat er één wordt gevonden waarvoor <code>callback</code> een waarde true teruggeeft. Als een dergelijk element wordt gevonden, geeft <code>find</code> direct de waarde van dat element terug. In andere gevallen geeft <code>find</code> {{jsxref("undefined")}} terug nadat alle elementen uit de array zijn doorlopen. <code>callback</code> wordt alleen aangeroepen voor indexen van de array waaraan een waarde is toegekend; de functie wordt niet aangeroepen voor indexen die zijn verwijderd of waaraan nooit een waarde is toegekend.</p> - -<p><code>callback</code> wordt aangeroepen met drie argumenten: de waarde van het element, de index van het element en het Array-object waarover wordt geïtereerd.</p> - -<p>Als een <code>thisArg</code>-parameter aan <code>find</code> wordt meegegeven, wordt deze voor elke aanroep van <code>callback</code> gebruikt als de waarde voor <code>this</code>. Als er geen waarde voor is opgegeven, wordt {{jsxref("undefined")}} gebruikt.</p> - -<p><code>find</code> wijzigt de array waarop de methode wordt aangeroepen niet.</p> - -<p>Het bereik van de elementen die door <code>find</code> worden verwerkt, wordt ingesteld voor de eerste aanroep van <code>callback</code>. Elementen die aan de array worden toegevoegd nadat de aanroep naar <code>find</code> begint, worden niet door <code>callback</code> bezocht. Als een bestaand, maar nog niet bezocht element van de array door <code>callback</code> wordt gewijzigd, zal de waarde van dit element die aan <code>callback</code> wordt meegegeven de waarde worden die eraan was toegekend op het moment dat <code>find</code> de index van dat element bereikte; verwijderde elementen worden niet bezocht.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Een_object_in_een_array_zoeken_via_een_van_zijn_eigenschappen">Een object in een array zoeken via een van zijn eigenschappen</h3> - -<pre class="brush: js">var voorraad = [ - {naam: 'appels', aantal: 2}, - {naam: 'bananen', aantal: 0}, - {naam: 'kersen', aantal: 5} -]; - -function zoekKersen(fruit) { - return fruit.naam === 'kersen'; -} - -console.log(voorraad.find(zoekKersen)); // { naam: 'kersen', aantal: 5 }</pre> - -<h3 id="Een_priemgetal_in_een_array_zoeken">Een priemgetal in een array zoeken</h3> - -<p>Het volgende voorbeeld zoekt een element in de array dat een priemgetal is (of geeft {{jsxref("undefined")}} terug als er geen priemgetal is).</p> - -<pre class="brush: js">function isPriem(element) { - var start = 2; - while (start <= Math.sqrt(element)) { - if (element % start++ < 1) { - return false; - } - } - return element > 1; -} - -console.log([4, 6, 8, 12].find(isPriem)); // niet gedefinieerd, niet gevonden -console.log([4, 5, 8, 12].find(isPriem)); // 5 -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>Deze methode is aan de ECMAScript 2015-specificatie toegevoegd en is mogelijk nog niet in alle JavaScript-implementaties beschikbaar. Met de volgende snippet kan <code>Array.prototype.find</code> echter worden ‘gepolyfilled’:</p> - -<pre class="brush: js">// https://tc39.github.io/ecma262/#sec-array.prototype.find -if (!Array.prototype.find) { - Object.defineProperty(Array.prototype, 'find', { - value: function(predicate) { - // 1. Let O be ? ToObject(this value). - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - - var o = Object(this); - - // 2. Let len be ? ToLength(? Get(O, "length")). - var len = o.length >>> 0; - - // 3. If IsCallable(predicate) is false, throw a TypeError exception. - if (typeof predicate !== 'function') { - throw new TypeError('predicate must be a function'); - } - - // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. - var thisArg = arguments[1]; - - // 5. Let k be 0. - var k = 0; - - // 6. Repeat, while k < len - while (k < len) { - // a. Let Pk be ! ToString(k). - // b. Let kValue be ? Get(O, Pk). - // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). - // d. If testResult is true, return kValue. - var kValue = o[k]; - if (predicate.call(thisArg, kValue, k, o)) { - return kValue; - } - // e. Increase k by 1. - k++; - } - - // 7. Return undefined. - return undefined; - } - }); -}</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.find', 'Array.prototype.find')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Eerste definitie.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.find', 'Array.prototype.find')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browsercompatibiliteit">Browsercompatibiliteit</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Functie</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Edge</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basisondersteuning</td> - <td>{{CompatChrome(45.0)}}</td> - <td>{{CompatGeckoDesktop("25.0")}}</td> - <td>{{CompatNo}}</td> - <td>12</td> - <td>{{CompatNo}}</td> - <td>{{CompatSafari("7.1")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Functie</th> - <th>Android</th> - <th>Chrome voor Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Edge</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basisondersteuning</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatGeckoMobile("25.0")}}</td> - <td>{{CompatNo}}</td> - <td>12</td> - <td>{{CompatNo}}</td> - <td>8.0</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.findIndex()")}}</li> - <li>{{jsxref("Array.prototype.every()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/findindex/index.html b/files/nl/web/javascript/reference/global_objects/array/findindex/index.html deleted file mode 100644 index 906d5465e2..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/findindex/index.html +++ /dev/null @@ -1,177 +0,0 @@ ---- -title: Array.prototype.findIndex() -slug: Web/JavaScript/Reference/Global_Objects/Array/findIndex -tags: - - Méthode -translation_of: Web/JavaScript/Reference/Global_Objects/Array/findIndex ---- -<div>{{JSRef}}</div> - -<p>De methode <code><strong>findIndex()</strong></code> geeft de <strong>index</strong> terug van het <strong>eerste element</strong> in de array waarvoor de gegeven functie voldoet. Indien er geen element wordt gevonden, zal -1 teruggegeven worden.</p> - -<div>{{EmbedInteractiveExample("pages/js/array-findindex.html")}}</div> - -<p class="hidden">De broncode van dit interactieve voorbeeld is terug te vinden in een GitHub repository. Als je wil bijdragen aan het interactieve voorbeelden project, clone dan <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> en stuur ons een pull request.</p> - -<div> </div> - -<p>Zie ook de methode {{jsxref("Array.find", "find()")}}, die een <strong>waarde</strong> teruggeeft van het gevonden element in plaats van de index.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>arr</var>.findIndex(<var>callback</var>[, <var>thisArg</var>])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>De functie die wordt uitgevoerd voor elk element in de array, met volgende drie argumenten: - <dl> - <dt><code>element</code></dt> - <dd>Het huidig te evalueren element uit de array.</dd> - <dt><code>index</code>{{optional_inline}}</dt> - <dd>De index van het huidig te evalueren element binnen de array.</dd> - <dt><code>array</code>{{optional_inline}}</dt> - <dd>De array waarop de methode <code>findIndex</code> was aangeroepen.</dd> - </dl> - </dd> - <dt><code>thisArg</code>{{optional_inline}}</dt> - <dd>Optioneel. Het object dat als <code>this</code> kan gebruikt worden tijdens de uitvoer van <code>callback</code>.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p>De index binnen de array van het gevonden element; anders, <strong>-1</strong>.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De methode <code>findIndex</code> voert de <code>callback</code> function uit voor elke index uit de array <code>0..length-1</code> (inclusief) tot wanneer er een element is waarvoor <code>callback</code> een waarde teruggeeft overeenkomstig met <code>true</code>. Als zo een element wordt gevonden, dan geeft <code>findIndex</code> onmiddellijk de index terug van deze iteratie. Als de functie voor geen enkel element voldoet of als <code>length</code> van de array 0 is, zal <code>findIndex</code> -1 teruggeven. In tegenstelling tot andere array methodes zoals Array#some, wordt <code>callback</code> ook aangeroepen ook voor indexen zonder element in de array.</p> - -<p><code>callback</code> heeft drie argumenten: de waarde van het element, de index van het element, en het Array element dat wordt doorlopen.</p> - -<p>Als een <code>thisArg</code> parameter wordt opgegeven voor <code>findIndex</code> zal het gebruikt worden als <code>this</code> bij elke aanroep van <code>callback</code>. Als het niet wordt opgegeven dan wordt {{jsxref("undefined")}} gebruikt.</p> - -<p><code>findIndex</code> past de array waarop het wordt aangeroepen niet aan.</p> - -<p>De reeks van elementen verwerkt door <code>findIndex</code> wordt opgemaakt voor de eerste aanroep van <code>callback</code>. Elementen die aan de array worden toegevoegd na de aanroep van <code>findIndex</code> zullen niet worden doorlopen door <code>callback</code>. Als een bestaand element, dat nog niet werd doorlopen, aangepast wordt door <code>callback</code>, dan zal deze waarde doorgegeven aan <code>callback</code>; verwijderde elementen worden ook doorlopen.</p> - -<h2 id="Examples">Examples</h2> - -<h3 id="Vind_de_index_van_een_priemgetal_in_een_array">Vind de index van een priemgetal in een array</h3> - -<p>Het volgende voorbeeld toont hoe een priemgetal kan gevonden worden in een array met getallen (of -1 als er geen priemgetal in de array zit).</p> - -<pre class="brush: js">function isPrime(element, index, array) { - var start = 2; - while (start <= Math.sqrt(element)) { - if (element % start++ < 1) { - return false; - } - } - return element > 1; -} - -console.log([4, 6, 8, 12].findIndex(isPrime)); // -1, not found -console.log([4, 6, 7, 12].findIndex(isPrime)); // 2 -</pre> - -<h3 id="Vind_index_met_een_arrow_function">Vind index met een arrow function</h3> - -<p>Het volgende voorbeeld toont hoe een element uit de array fruits kan gevonden worden met de arrow function syntax.</p> - -<pre class="brush: js">const fruits = ["apple", "banana", "cantaloupe", "blueberries", "grapefruit"]; - -const index = fruits.findIndex(fruit => fruit === "blueberries"); - -console.log(index); // 3 -console.log(fruits[index]); // blueberries -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<pre class="brush: js">// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex -if (!Array.prototype.findIndex) { - Object.defineProperty(Array.prototype, 'findIndex', { - value: function(predicate) { - // 1. Let O be ? ToObject(this value). - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - - var o = Object(this); - - // 2. Let len be ? ToLength(? Get(O, "length")). - var len = o.length >>> 0; - - // 3. If IsCallable(predicate) is false, throw a TypeError exception. - if (typeof predicate !== 'function') { - throw new TypeError('predicate must be a function'); - } - - // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. - var thisArg = arguments[1]; - - // 5. Let k be 0. - var k = 0; - - // 6. Repeat, while k < len - while (k < len) { - // a. Let Pk be ! ToString(k). - // b. Let kValue be ? Get(O, Pk). - // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). - // d. If testResult is true, return k. - var kValue = o[k]; - if (predicate.call(thisArg, kValue, k, o)) { - return k; - } - // e. Increase k by 1. - k++; - } - - // 7. Return -1. - return -1; - }, - configurable: true, - writable: true - }); -} -</pre> - -<p>Als je echt verouderde JavaScript engines moet blijven ondersteunen die <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a></code> niet supporteren, is het beter van <code>Array.prototype</code> methodes helemaal niet te voorzien als polyfill, omdat je ze toch niet niet-enumereerbaar kan maken.</p> - -<h2 id="Specificaties">Specificaties</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-array.prototype.findindex', 'Array.prototype.findIndex')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.findIndex', 'Array.prototype.findIndex')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div> -<div class="hidden">De compatibility tabel van deze pagina werd gegenereerd uit gestructureerde data. Als je wil bijdragen verwijzen we naar <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> en stuur ons een pull request.</div> - -<p>{{Compat("javascript.builtins.Array.findIndex")}}</p> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.find()")}}</li> - <li>{{jsxref("Array.prototype.indexOf()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/includes/index.html b/files/nl/web/javascript/reference/global_objects/array/includes/index.html deleted file mode 100644 index 104c9a7705..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/includes/index.html +++ /dev/null @@ -1,220 +0,0 @@ ---- -title: Array.prototype.includes() -slug: Web/JavaScript/Reference/Global_Objects/Array/includes -translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes ---- -<div>{{JSRef}}</div> - -<p>De methode <code><strong>includes()</strong></code> controleert of de opgegeven waarde aanwezig is in een reeks of niet. Als dit waar is geeft het <code>true</code>, anders <code>false</code>.</p> - -<pre class="brush: js">var a = [1, 2, 3]; -a.includes(2); // true -a.includes(4); // false</pre> - -<h2 id="Syntax">Syntax</h2> - -<pre><var>arr</var>.includes(<var>zoekWaarde[</var>, <var>vanIndex]</var>)</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>zoekWaarde</code></dt> - <dd>Het element om te zoeken.</dd> - <dt><code>vanIndex</code> {{optional_inline}}</dt> - <dd>De positie binnen de array waar begonnen wordt met het zoeken naar <code>zoekWaarde</code>. Een negatieve waarde zoekt oplopend uit de index van array.length + vanIndex. Standaard 0.</dd> -</dl> - -<h3 id="Antwoord_waarde">Antwoord waarde</h3> - -<p>Een {{jsxref("Boolean")}}. <code>true</code> als de <code>zoekWaarde</code> is gevonden. <code>false</code> als dit niet het geval is. de 0 (nul) worden als gelijk gezien. -0 is gelijk aan 0 en +0. <code>false</code> staat niet gelijk aan 0</p> - -<p><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 40px;"><strong>Voorbeelden</strong></span></font></p> - -<p> </p> - -<pre class="brush: js">[1, 2, 3].includes(2); // true <em>(waar)</em> -[1, 2, 3].includes(4); // false <em>(niet waar)</em> -[1, 2, 3].includes(3, 3); // false <em>(niet waar)</em> -[1, 2, 3].includes(3, -1); // true <em>(waar)</em> -[1, 2, NaN].includes(NaN); // true <em>(waar) </em>(NaN betekent "Not A Number" oftewel "geen nummer" in het Engels) -</pre> - -<p> </p> - -<h3 id="fromIndex_is_groter_dan_of_gelijk_aan_de_array_lengte"><code>fromIndex</code> is groter dan of gelijk aan de array lengte</h3> - -<p>Als <code>fromIndex</code> groter of gelijk is aan de lengte van de array, wordt er <code>false</code> geantwoord. De array zal niet doorzocht worden.</p> - -<pre class="brush: js">var arr = ['a', 'b', 'c']; - -arr.includes('c', 3); // false <em>(niet waar)</em> -arr.includes('c', 100); // false <em>(niet waar)</em></pre> - -<h3 id="De_berekende_index_is_minder_dan_0">De berekende index is minder dan 0</h3> - -<p>Als <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.498039);">vanIndex</span></font> negatief is, zal de berekende index worden berekend om te worden gebruikt als een positie in de array waarop moet worden gezocht naar <code>zoekElement</code>. Als de berekende index lager is dan 0, wordt de hele array doorzocht.</p> - -<pre class="brush: js">// array lengte is 3 -// vanIndex is -100 -// berekende index is 3 + (-100) = -97 - -var arr = ['a', 'b', 'c']; - -arr.includes('a', -100); // true <em>(waar)</em> -arr.includes('b', -100); // true <em>(waar)</em> -arr.includes('c', -100); // true <em>(waar)</em></pre> - -<h3 id="includes()_gebruiken_als_een_algemene_methode"><code>includes()</code> gebruiken als een algemene methode</h3> - -<p>De <code>includes()</code> methode is natuurlijk algemeen. Het is niet nodig dat <code>deze</code> waarde een Array is. Het onderstaande voorbeeld laat de <code>includes()</code> methode zien in een functie's <a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">argumenten</a> lijst. </p> - -<pre class="brush: js">(function() { - console.log([].includes.call(arguments, 'a')); // true <em>(waar)</em> - console.log([].includes.call(arguments, 'd')); // false <em>(niet waar)</em> -})('a','b','c');</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<pre class="brush: js">// https://tc39.github.io/ecma262/#sec-array.prototype.includes -if (!Array.prototype.includes) { - Object.defineProperty(Array.prototype, 'includes', { - value: function(searchElement, fromIndex) { - - // 1. Let O be ? ToObject(this value). - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - - var o = Object(this); - - // 2. Let len be ? ToLength(? Get(O, "length")). - var len = o.length >>> 0; - - // 3. If len is 0, return false. - if (len === 0) { - return false; - } - - // 4. Let n be ? ToInteger(fromIndex). - // (If fromIndex is undefined, this step produces the value 0.) - var n = fromIndex | 0; - - // 5. If n ≥ 0, then - // a. Let k be n. - // 6. Else n < 0, - // a. Let k be len + n. - // b. If k < 0, let k be 0. - var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); - - // 7. Repeat, while k < len - while (k < len) { - // a. Let elementK be the result of ? Get(O, ! ToString(k)). - // b. If SameValueZero(searchElement, elementK) is true, return true. - // c. Increase k by 1. - // NOTE: === provides the correct "SameValueZero" comparison needed here. - if (o[k] === searchElement) { - return true; - } - k++; - } - - // 8. Return false - return false; - } - }); -} -</pre> - -<p>If you need to support truly obsolete JavaScript engines that don't support <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a></code>, it's best not to polyfill <code>Array.prototype</code> methods at all, as you can't make them non-enumerable.</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>{{SpecName('ES7', '#sec-array.prototype.includes', 'Array.prototype.includes')}}</td> - <td>{{Spec2('ES7')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}</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>Edge</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td> - <p>{{CompatChrome(47)}}</p> - </td> - <td>{{CompatGeckoDesktop("43")}}</td> - <td>{{CompatNo}}</td> - <td>14</td> - <td>34</td> - <td>9</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> - <p>{{CompatChrome(47)}}</p> - </td> - <td>{{CompatGeckoMobile("43")}}</td> - <td>{{CompatNo}}</td> - <td>34</td> - <td>9</td> - <td> - <p>{{CompatChrome(47)}}</p> - </td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("TypedArray.prototype.includes()")}}</li> - <li>{{jsxref("String.prototype.includes()")}}</li> - <li>{{jsxref("Array.prototype.indexOf()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/index.html b/files/nl/web/javascript/reference/global_objects/array/index.html deleted file mode 100644 index 37394ccd2e..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/index.html +++ /dev/null @@ -1,485 +0,0 @@ ---- -title: Array -slug: Web/JavaScript/Reference/Global_Objects/Array -tags: - - Array - - JavaScript - - NeedsTranslation - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/Array ---- -<div>{{JSRef}}</div> - -<p>De JavaScript <strong><code>Array</code></strong> klasse is een globaal object dat wordt gebruikt bij de constructie van arrays; <a href="https://developer.mozilla.org/en-US/docs/Glossary/High-level_programming_language">een hoog-geplaatst</a>, lijstachtig object.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>Arrays zijn lijstachtige objecten waarvan het prototype methoden heeft om te iterereren, muteren en kopiëren. Noch de lengte van een Javascript-array, noch de typen elementen staan vast. Aangezien de lengte van een array op elk moment kan veranderen en gegevens kunnen worden opgeslagen op niet-aangrenzende locaties, is het niet gegarandeerd dat de gegevensplekken in de Javascript-array vast staan. Over het algemeen zijn dit handige kenmerken; maar als deze functies niet wenselijk zijn voor jouw specifieke gebruik, kun je overwegen om <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays">Typed Arrays</a> te gebruiken.</p> - -<p>Arrays kunnen geen tekenreeksen gebruiken als elementindexen (zoals in een associatieve array), maar moeten hele getallen gebruiken. Een element instellen of ophalen met behulp van de haakjesnotatie <em>(of puntnotatie) </em>zal geen element uit de array ophalen of instellen. Maar zal proberen om een variabele uit de <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Properties">object property collection</a> van de array op te halen of in te stellen. De objecteigenschappen van de array en de lijst met arrayelementen zijn namelijk gescheiden en de kopie- en mutatiebewerkingen van de array kunnen niet worden toegepast op deze benoemde eigenschappen</p> - -<h3 id="Alledaagse_handelingen">Alledaagse handelingen</h3> - -<p><strong>Maak een Array aan</strong></p> - -<pre class="brush: js">let fruit = ["Appel", "Banaan"]; - -console.log(fruit.length); -// 2 -</pre> - -<p><strong>Toegang tot (indexeren van) een Array-item</strong></p> - -<pre class="brush: js">let eerste = fruit[0]; -// Appel - -let laatste = fruit[fruit.length - 1]; -// Banaan -</pre> - -<p><strong>Itereer over een Array</strong></p> - -<pre class="brush: js">fruit.forEach(function (item, index, array) { - console.log(item, index); -}); -// Appel 0 -// Banaan 1 -</pre> - -<p><strong>Toevoegen op het eind van de Array</strong></p> - -<pre class="brush: js">let nieuweLengte = fruit.push("Sinaasappel"); -// ["Appel", "Banaan", "Sinaasappel"] -</pre> - -<p><strong>Verwijder op het eind van de Array</strong></p> - -<pre class="brush: js">let laatste = fruit.pop(); // verwijder de Sinaasappel op het eind -// ["Appel", "Banaan"]; -</pre> - -<p><strong>Verwijder van de eerste plaats van een array</strong></p> - -<pre class="brush: js">let eerste = fruit.shift(); // verwijder appel van de eerste plaats -// ["Banaan"]; -</pre> - -<p><strong>Voeg toe aan de eerste plaats van een Array</strong></p> - -<pre class="brush: js">let nieuweLengte = fruit.unshift("Aardbei") // voeg de aarbei toe op de eerste plaats -// ["Aardbei", "Banaan"]; -</pre> - -<p><strong>Zoek de index van een item in de Array</strong></p> - -<pre class="brush: js">fruit.push("Mango"); -// ["Aardbei", "Banaan", "Mango"] - -let positie = fruit.indexOf("Banaan"); -// 1 -</pre> - -<p><strong>Verwijder een item van de indexpositie</strong></p> - -<pre class="brush: js">let verwijderItem = fruit.splice(positie, 1); // hiermee kan je een item verwijderen -// ["Aardbei", "Mango"] -</pre> - -<p><strong>Kopieer een array</strong></p> - -<pre class="brush: js">let Kopie = fruit.slice(); // hiermee maak je een kopie van de matrix -// ["Aardbei", "Mango"] -</pre> - -<h2 id="Syntaxis">Syntaxis</h2> - -<pre class="syntaxbox"><code>[<var>element0</var>, <var>element1</var>, ..., <var>elementN</var>] -new Array(<var>element0</var>, <var>element1</var>[, ...[, <var>elementN</var>]]) -new Array(<var>arrayLength</var>)</code></pre> - -<dl> - <dt><code>element<em>N</em></code></dt> - <dd>Een JavaScript-array wordt geïnitialiseerd met de gegeven elementen, behalve in het geval dat een enkel argument wordt doorgegeven aan de Array-constructor en dat argument een getal is. (Zie hieronder.) Merk op dat dit speciale geval alleen van toepassing is op JavaScript-arrays die zijn gemaakt met de Array-constructor, niet op array-literals die zijn gemaakt met de haakjesyntaxis.</dd> - <dt><code>arrayLengte</code></dt> - <dd>Als het enige argument dat aan de constructor Array is doorgegeven, een geheel getal tussen 0 en 232-1 (inclusief) is, geeft dit een nieuwe JavaScript-array terug waarvan de lengte is ingesteld op dat aantal. Als het argument een ander getal is, wordt er een uitzondering {{jsxref ("RangeError")}} gegenereerd.</dd> - <dt></dt> -</dl> - -<h3 id="Toegang_tot_array-elementen">Toegang tot array-elementen</h3> - -<p>JavaScript-arrays zijn geïndexeerd vanaf nul: het eerste element van een array staat op index 0 en het laatste element staat op de index die gelijk is aan de waarde van de eigenschap {{jsxref ("Array.length", "length")}} van de array min 1.</p> - -<pre class="brush: js">var arr = ['this is the first element', 'this is the second element']; -console.log(arr[0]); // logs 'this is the first element' -console.log(arr[1]); // logs 'this is the second element' -console.log(arr[arr.length - 1]); // logs 'this is the second element' -</pre> - -<p>Array elements are object properties in the same way that <code>toString</code> is a property, but trying to access an element of an array as follows throws a syntax error, because the property name is not valid:</p> - -<pre class="brush: js">console.log(arr.0); // a syntax error -</pre> - -<p>There is nothing special about JavaScript arrays and the properties that cause this. JavaScript properties that begin with a digit cannot be referenced with dot notation; and must be accessed using bracket notation. For example, if you had an object with a property named <code>'3d'</code>, it can only be referenced using bracket notation. E.g.:</p> - -<pre class="brush: js">var years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]; -console.log(years.0); // a syntax error -console.log(years[0]); // works properly -</pre> - -<pre class="brush: js">renderer.3d.setTexture(model, 'character.png'); // a syntax error -renderer['3d'].setTexture(model, 'character.png'); // works properly -</pre> - -<p>Note that in the <code>3d</code> example, <code>'3d'</code> had to be quoted. It's possible to quote the JavaScript array indexes as well (e.g., <code>years['2']</code> instead of <code>years[2]</code>), although it's not necessary. The 2 in <code>years[2]</code> is coerced into a string by the JavaScript engine through an implicit <code>toString</code> conversion. It is for this reason that <code>'2'</code> and <code>'02'</code> would refer to two different slots on the <code>years</code> object and the following example could be <code>true</code>:</p> - -<pre class="brush: js">console.log(years['2'] != years['02']); -</pre> - -<p>Similarly, object properties which happen to be reserved words(!) can only be accessed as string literals in bracket notation(but it can be accessed by dot notation in firefox 40.0a2 at least):</p> - -<pre class="brush: js">var promise = { - 'var' : 'text', - 'array': [1, 2, 3, 4] -}; - -console.log(promise['array']); -</pre> - -<h3 id="Relationship_between_length_and_numerical_properties">Relationship between <code>length</code> and numerical properties</h3> - -<p>A JavaScript array's {{jsxref("Array.length", "length")}} property and numerical properties are connected. Several of the built-in array methods (e.g., {{jsxref("Array.join", "join")}}, {{jsxref("Array.slice", "slice")}}, {{jsxref("Array.indexOf", "indexOf")}}, etc.) take into account the value of an array's {{jsxref("Array.length", "length")}} property when they're called. Other methods (e.g., {{jsxref("Array.push", "push")}}, {{jsxref("Array.splice", "splice")}}, etc.) also result in updates to an array's {{jsxref("Array.length", "length")}} property.</p> - -<pre class="brush: js">var fruits = []; -fruits.push('banana', 'apple', 'peach'); - -console.log(fruits.length); // 3 -</pre> - -<p>When setting a property on a JavaScript array when the property is a valid array index and that index is outside the current bounds of the array, the engine will update the array's {{jsxref("Array.length", "length")}} property accordingly:</p> - -<pre class="brush: js">fruits[5] = 'mango'; -console.log(fruits[5]); // 'mango' -console.log(Object.keys(fruits)); // ['0', '1', '2', '5'] -console.log(fruits.length); // 6 -</pre> - -<p>Increasing the {{jsxref("Array.length", "length")}}.</p> - -<pre class="brush: js">fruits.length = 10; -console.log(Object.keys(fruits)); // ['0', '1', '2', '5'] -console.log(fruits.length); // 10 -</pre> - -<p>Decreasing the {{jsxref("Array.length", "length")}} property does, however, delete elements.</p> - -<pre class="brush: js">fruits.length = 2; -console.log(Object.keys(fruits)); // ['0', '1'] -console.log(fruits.length); // 2 -</pre> - -<p>This is explained further on the {{jsxref("Array.length")}} page.</p> - -<h3 id="Creating_an_array_using_the_result_of_a_match">Creating an array using the result of a match</h3> - -<p>The result of a match between a regular expression and a string can create a JavaScript array. This array has properties and elements which provide information about the match. Such an array is returned by {{jsxref("RegExp.exec")}}, {{jsxref("String.match")}}, and {{jsxref("String.replace")}}. To help explain these properties and elements, look at the following example and then refer to the table below:</p> - -<pre class="brush: js">// Match one d followed by one or more b's followed by one d -// Remember matched b's and the following d -// Ignore case - -var myRe = /d(b+)(d)/i; -var myArray = myRe.exec('cdbBdbsbz'); -</pre> - -<p>The properties and elements returned from this match are as follows:</p> - -<table class="fullwidth-table"> - <tbody> - <tr> - <td class="header">Property/Element</td> - <td class="header">Description</td> - <td class="header">Example</td> - </tr> - <tr> - <td><code>input</code></td> - <td>A read-only property that reflects the original string against which the regular expression was matched.</td> - <td>cdbBdbsbz</td> - </tr> - <tr> - <td><code>index</code></td> - <td>A read-only property that is the zero-based index of the match in the string.</td> - <td>1</td> - </tr> - <tr> - <td><code>[0]</code></td> - <td>A read-only element that specifies the last matched characters.</td> - <td>dbBd</td> - </tr> - <tr> - <td><code>[1], ...[n]</code></td> - <td>Read-only elements that specify the parenthesized substring matches, if included in the regular expression. The number of possible parenthesized substrings is unlimited.</td> - <td>[1]: bB<br> - [2]: d</td> - </tr> - </tbody> -</table> - -<h2 id="Properties">Properties</h2> - -<dl> - <dt><code>Array.length</code></dt> - <dd>The <code>Array</code> constructor's length property whose value is 1.</dd> - <dt>{{jsxref("Array.prototype")}}</dt> - <dd>Allows the addition of properties to all array objects.</dd> -</dl> - -<h2 id="Methods">Methods</h2> - -<dl> - <dt>{{jsxref("Array.from()")}}</dt> - <dd>Creates a new <code>Array</code> instance from an array-like or iterable object.</dd> - <dt>{{jsxref("Array.isArray()")}}</dt> - <dd>Returns true if a variable is an array, if not false.</dd> - <dt>{{jsxref("Array.observe()")}} {{non-standard_inline}}</dt> - <dd>Asynchronously observes changes to Arrays, similar to {{jsxref("Object.observe()")}} for objects. It provides a stream of changes in order of occurrence.</dd> - <dt>{{jsxref("Array.of()")}}</dt> - <dd>Creates a new <code>Array</code> instance with a variable number of arguments, regardless of number or type of the arguments.</dd> -</dl> - -<h2 id="Array_instances"><code>Array</code> instances</h2> - -<p>All <code>Array</code> instances inherit from {{jsxref("Array.prototype")}}. The prototype object of the <code>Array</code> constructor can be modified to affect all <code>Array</code> instances.</p> - -<h3 id="Properties_2">Properties</h3> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Properties')}}</div> - -<h3 id="Methods_2">Methods</h3> - -<h4 id="Mutator_methods">Mutator methods</h4> - -<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Mutator_methods')}}</div> - -<h4 id="Accessor_methods">Accessor methods</h4> - -<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Accessor_methods')}}</div> - -<h4 id="Iteration_methods">Iteration methods</h4> - -<div>{{page('en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype', 'Iteration_methods')}}</div> - -<h2 id="Array_generic_methods"><code>Array</code> generic methods</h2> - -<div class="warning"> -<p><strong>Array generics are non-standard, deprecated and will get removed near future</strong>. Note that you can not rely on them cross-browser. However, there is a <a href="https://github.com/plusdude/array-generics">shim available on GitHub</a>.</p> -</div> - -<p>Sometimes you would like to apply array methods to strings or other array-like objects (such as function {{jsxref("Functions/arguments", "arguments", "", 1)}}). By doing this, you treat a string as an array of characters (or otherwise treat a non-array as an array). For example, in order to check that every character in the variable <var>str</var> is a letter, you would write:</p> - -<pre class="brush: js">function isLetter(character) { - return character >= 'a' && character <= 'z'; -} - -if (Array.prototype.every.call(str, isLetter)) { - console.log("The string '" + str + "' contains only letters!"); -} -</pre> - -<p>This notation is rather wasteful and JavaScript 1.6 introduced a generic shorthand:</p> - -<pre class="brush: js">if (Array.every(str, isLetter)) { - console.log("The string '" + str + "' contains only letters!"); -} -</pre> - -<p>{{jsxref("Global_Objects/String", "Generics", "#String_generic_methods", 1)}} are also available on {{jsxref("String")}}.</p> - -<p>These are <strong>not</strong> part of ECMAScript standards (though the ES6 {{jsxref("Array.from()")}} can be used to achieve this). The following is a shim to allow its use in all browsers:</p> - -<pre class="brush: js">// Assumes Array extras already present (one may use polyfills for these as well) -(function() { - 'use strict'; - - var i, - // We could also build the array of methods with the following, but the - // getOwnPropertyNames() method is non-shimable: - // Object.getOwnPropertyNames(Array).filter(function(methodName) { - // return typeof Array[methodName] === 'function' - // }); - methods = [ - 'join', 'reverse', 'sort', 'push', 'pop', 'shift', 'unshift', - 'splice', 'concat', 'slice', 'indexOf', 'lastIndexOf', - 'forEach', 'map', 'reduce', 'reduceRight', 'filter', - 'some', 'every', 'find', 'findIndex', 'entries', 'keys', - 'values', 'copyWithin', 'includes' - ], - methodCount = methods.length, - assignArrayGeneric = function(methodName) { - if (!Array[methodName]) { - var method = Array.prototype[methodName]; - if (typeof method === 'function') { - Array[methodName] = function() { - return method.call.apply(method, arguments); - }; - } - } - }; - - for (i = 0; i < methodCount; i++) { - assignArrayGeneric(methods[i]); - } -}()); -</pre> - -<h2 id="Examples">Examples</h2> - -<h3 id="Creating_an_array">Creating an array</h3> - -<p>The following example creates an array, <code>msgArray</code>, with a length of 0, then assigns values to <code>msgArray[0]</code> and <code>msgArray[99]</code>, changing the length of the array to 100.</p> - -<pre class="brush: js">var msgArray = []; -msgArray[0] = 'Hello'; -msgArray[99] = 'world'; - -if (msgArray.length === 100) { - console.log('The length is 100.'); -} -</pre> - -<h3 id="Creating_a_two-dimensional_array">Creating a two-dimensional array</h3> - -<p>The following creates a chess board as a two dimensional array of strings. The first move is made by copying the 'p' in (6,4) to (4,4). The old position (6,4) is made blank.</p> - -<pre class="brush: js">var board = [ - ['R','N','B','Q','K','B','N','R'], - ['P','P','P','P','P','P','P','P'], - [' ',' ',' ',' ',' ',' ',' ',' '], - [' ',' ',' ',' ',' ',' ',' ',' '], - [' ',' ',' ',' ',' ',' ',' ',' '], - [' ',' ',' ',' ',' ',' ',' ',' '], - ['p','p','p','p','p','p','p','p'], - ['r','n','b','q','k','b','n','r'] ]; - -console.log(board.join('\n') + '\n\n'); - -// Move King's Pawn forward 2 -board[4][4] = board[6][4]; -board[6][4] = ' '; -console.log(board.join('\n')); -</pre> - -<p>Here is the output:</p> - -<pre class="eval">R,N,B,Q,K,B,N,R -P,P,P,P,P,P,P,P - , , , , , , , - , , , , , , , - , , , , , , , - , , , , , , , -p,p,p,p,p,p,p,p -r,n,b,q,k,b,n,r - -R,N,B,Q,K,B,N,R -P,P,P,P,P,P,P,P - , , , , , , , - , , , , , , , - , , , ,p, , , - , , , , , , , -p,p,p,p, ,p,p,p -r,n,b,q,k,b,n,r -</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-15.4', 'Array')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>New methods added: {{jsxref("Array.isArray")}}, {{jsxref("Array.prototype.indexOf", "indexOf")}}, {{jsxref("Array.prototype.lastIndexOf", "lastIndexOf")}}, {{jsxref("Array.prototype.every", "every")}}, {{jsxref("Array.prototype.some", "some")}}, {{jsxref("Array.prototype.forEach", "forEach")}}, {{jsxref("Array.prototype.map", "map")}}, {{jsxref("Array.prototype.filter", "filter")}}, {{jsxref("Array.prototype.reduce", "reduce")}}, {{jsxref("Array.prototype.reduceRight", "reduceRight")}}</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array-objects', 'Array')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>New methods added: {{jsxref("Array.from")}}, {{jsxref("Array.of")}}, {{jsxref("Array.prototype.find", "find")}}, {{jsxref("Array.prototype.findIndex", "findIndex")}}, {{jsxref("Array.prototype.fill", "fill")}}, {{jsxref("Array.prototype.copyWithin", "copyWithin")}}</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array-objects', 'Array')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td>New method added: {{jsxref("Array.prototype.includes()")}}</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>{{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><a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Indexing_object_properties">JavaScript Guide: “Indexing object properties”</a></li> - <li><a href="/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects#Array_Object">JavaScript Guide: “Predefined Core Objects: <code>Array</code> Object”</a></li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions">Array comprehensions</a></li> - <li><a href="https://github.com/plusdude/array-generics">Polyfill for JavaScript 1.8.5 Array Generics and ECMAScript 5 Array Extras</a></li> - <li><a href="/en-US/docs/JavaScript_typed_arrays">Typed Arrays</a></li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/indexof/index.html b/files/nl/web/javascript/reference/global_objects/array/indexof/index.html deleted file mode 100644 index 19d72e4ec5..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/indexof/index.html +++ /dev/null @@ -1,244 +0,0 @@ ---- -title: Array.prototype.indexOf() -slug: Web/JavaScript/Reference/Global_Objects/Array/indexOf -tags: - - Array - - Méthode - - indexof - - zoeken -translation_of: Web/JavaScript/Reference/Global_Objects/Array/indexOf ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>indexOf()</strong></code> methode retourneert het index getal behorende bij het gegeven element in een array. Indien het element niet is gevonden wordt -1 geretourneerd.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>arr</var>.indexOf(<var>searchElement</var>[, <var>fromIndex</var> = 0])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>searchElement</code></dt> - <dd>Het te doorzoeken element in de Array.</dd> - <dt><code>fromIndex</code></dt> - <dd>De index waar vanaf gezocht moet worden. Als de index groter is dan de lengte van de array, dan wordt -1 geretourneerd welke inhoudt dat de array niet doorzocht is. Als de gegeven index een negatief getal is, wordt dit gebruikt als offset van het einde van de array. Opmerking: Als de gegeven index negatief is, wordt de array nog steeds van voren naar achteren doorzocht. Als de berekende index minder dan 0 is, dan wordt de gehele array doorzocht. Standaard: 0 (gehele array wordt doorzocht).</dd> -</dl> - -<h3 id="Return_waarde">Return waarde</h3> - -<p>De eerste index van het element in de array; <strong>-1</strong> als het element niet is gevonden.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p><code><strong>indexOf()</strong></code> vergelijkt searchElement met elementen van de Array gebruikmakend van 'strict equality' (dezelfde methode zoals gebruikt door === of de gelijk-aan operator).</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Het_gebruik_van_indexOf()"><code>Het gebruik van indexOf()</code></h3> - -<p>De volgende voorbeelden gebruiken <code><strong>indexOf()</strong></code> om waarden in een array te lokalizeren. </p> - -<pre class="brush: js">var array = [2, 9, 9]; -array.indexOf(2); // 0 -array.indexOf(7); // -1 -array.indexOf(9, 2); // 2 -array.indexOf(2, -1); // -1 -array.indexOf(2, -3); // 0 -</pre> - -<h3 id="Alle_voorvallen_vinden_van_een_element">Alle voorvallen vinden van een element</h3> - -<pre class="brush: js">var indices = []; -var array = ['a', 'b', 'a', 'c', 'a', 'd']; -var element = 'a'; -var idx = array.indexOf(element); -while (idx != -1) { - indices.push(idx); - idx = array.indexOf(element, idx + 1); -} -console.log(indices); -// [0, 2, 4] -</pre> - -<h3 id="Zoek_of_een_element_bestaat_in_de_array_of_niet_en_update_de_array">Zoek of een element bestaat in de array of niet en update de array</h3> - -<pre class="brush: js">function updateVegetablesCollection (veggies, veggie) { - if (veggies.indexOf(veggie) === -1) { - veggies.push(veggie); - console.log('New veggies collection is : ' + veggies); - } else if (veggies.indexOf(veggie) > -1) { - console.log(veggie + ' already exists in the veggies collection.'); - } -} - -var veggies = ['potato', 'tomato', 'chillies', 'green-pepper']; - -updateVegetablesCollection(veggies, 'spinach'); -// New veggies collection is : potato,tomato,chillies,green-papper,spinach -updateVegetablesCollection(veggies, 'spinach'); -// spinach already exists in the veggies collection. -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p><strong><code>indexOf()</code></strong> werd aan de ECMA-262 standaard toegevoegd in de 5de editie; als zodanig kan het niet in alle browsers voorkomen. U kunt hier een workaround voor gebruiken door de volgende code te plaatsen in het begin van uw scripts. Hiermee kunt u <code><strong>indexOf()</strong> </code>gebruiken als er nog geen native support beschikbaar is. Dit algoritme vergelijkt hetgeen gespecificeerd in ECMA-262, 5de editie, aangenomen dat {{jsxref("Global_Objects/TypeError", "TypeError")}} en {{jsxref("Math.abs()")}} hun eigen waarden hebben.</p> - -<pre class="brush: js">// Production steps of ECMA-262, Edition 5, 15.4.4.14 -// Referentie: http://es5.github.io/#x15.4.4.14 -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function(searchElement, fromIndex) { - - var k; - - // 1. Let o be the result of calling ToObject passing - // the this value as the argument. - if (this == null) { - throw new TypeError('"this" is null or not defined'); - } - - var o = Object(this); - - // 2. Let lenValue be the result of calling the Get - // internal method of o with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = o.length >>> 0; - - // 4. If len is 0, return -1. - if (len === 0) { - return -1; - } - - // 5. If argument fromIndex was passed let n be - // ToInteger(fromIndex); else let n be 0. - var n = +fromIndex || 0; - - if (Math.abs(n) === Infinity) { - n = 0; - } - - // 6. If n >= len, return -1. - if (n >= len) { - return -1; - } - - // 7. Als n >= 0, dan Let k be n. - // 8. Anders, n<0, Let k be len - abs(n). - // Als k kleiner is dan 0, dan let k be 0. - k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); - - // 9. Herhaal, zolang k < len - while (k < len) { - // a. Let Pk be ToString(k). - // Dit is impliciet voor de linkerkant van de vergelijking - // b. Let kPresent be the result of calling the - // HasProperty internal method of o with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - // i. Let elementK be the result of calling the Get - // internal method of o with the argument ToString(k). - // ii. Let same be the result of applying the - // Strict Equality Comparison Algorithm to - // searchElement and elementK. - // iii. If same is true, return k. - if (k in o && o[k] === searchElement) { - return k; - } - k++; - } - return -1; - }; -} -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.14', 'Array.prototype.indexOf')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Oorspronkelijke definitie. Geïmplementeerd in JavaScript 1.6.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.indexof', 'Array.prototype.indexOf')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.indexof', 'Array.prototype.indexOf')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browsercompatibiliteit">Browsercompatibiliteit</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Kenmerk</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basis Ondersteuning</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("1.8")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Kenmerk</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>Basis Ondersteuning</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile("1.8")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Compatibiliteit_opmerkingen">Compatibiliteit opmerkingen</h2> - -<ul> - <li>Vanaf Firefox 47 {{geckoRelease(47)}}, retourneert deze methode niet meer <code>-0</code>. Bijvoorbeeld, <code>[0].indexOf(0, -0)</code> retourneert nu <code>+0</code> ({{bug(1242043)}}).</li> -</ul> - -<h2 id="Bekijk_ook">Bekijk ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.lastIndexOf()")}}</li> - <li>{{jsxref("TypedArray.prototype.indexOf()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/isarray/index.html b/files/nl/web/javascript/reference/global_objects/array/isarray/index.html deleted file mode 100644 index 19566a4ced..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/isarray/index.html +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: Array.isArray() -slug: Web/JavaScript/Reference/Global_Objects/Array/isArray -translation_of: Web/JavaScript/Reference/Global_Objects/Array/isArray ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>Array.isArray()</strong></code> bepaalt of de gegeven waarde een {{jsxref("Array")}} is. </p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>Array.isArray(<var>obj</var>)</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>obj</code></dt> - <dd>Het te onderzoeken object.</dd> -</dl> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>Indien het object een {{jsxref("Array")}} is, dan is <code>true</code> het resultaat, anders wordt dit <code>false</code>. </p> - -<p>Bekijk het artikel <a href="http://web.mit.edu/jwalden/www/isArray.html">“Determining with absolute accuracy whether or not a JavaScript object is an array”</a> voor nadere details.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<pre class="brush: js">// alle van de volgende call resulteren in true -Array.isArray([]); -Array.isArray([1]); -Array.isArray(new Array()); -// Weinig bekend: Array.prototype is zelf een array: -Array.isArray(Array.prototype); - -// alle van de volgende calls resulteren in false -Array.isArray(); -Array.isArray({}); -Array.isArray(null); -Array.isArray(undefined); -Array.isArray(17); -Array.isArray('Array'); -Array.isArray(true); -Array.isArray(false); -Array.isArray({ __proto__: Array.prototype }); -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>De volgende code zal de methode <code>Array.isArray()</code> aanmaken indien deze niet van huis uit werd meegegeven:</p> - -<pre class="brush: js">if (!Array.isArray) { - Array.isArray = function(arg) { - return Object.prototype.toString.call(arg) === '[object Array]'; - }; -} -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificaties</th> - <th scope="col">Status</th> - <th scope="col">Commentaar</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.3.2', 'Array.isArray')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Initiele definitie. Geimplementeerd in JavaScript 1.8.5.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.isarray', 'Array.isArray')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.isarray', 'Array.isArray')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Eigenschap</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("5")}}</td> - <td>{{CompatGeckoDesktop("2.0")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatOpera("10.5")}}</td> - <td>{{CompatSafari("5")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Eigenschap</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>{{CompatGeckoMobile("2.0")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/map/index.html b/files/nl/web/javascript/reference/global_objects/array/map/index.html deleted file mode 100644 index 8ac69797ad..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/map/index.html +++ /dev/null @@ -1,324 +0,0 @@ ---- -title: Array.prototype.map() -slug: Web/JavaScript/Reference/Global_Objects/Array/map -tags: - - ECMAScript6 - - JavaScript - - Méthode - - Prototype - - Referentie - - polyfill - - reeks -translation_of: Web/JavaScript/Reference/Global_Objects/Array/map ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>map()</strong></code> methode <strong>maakt een nieuwe array aan</strong> met als inhoud het resultaat van het aanroepen van de meegegeven functie op elk van de elementen uit de originele array.</p> - -<div>{{EmbedInteractiveExample("pages/js/array-map.html")}}</div> - -<p class="hidden">De broncode voor dit interactieve voorbeeld is opgeslagen in een GitHub-repository. Als u wilt bijdragen aan het interactieve voorbeeldproject, kunt u <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> klonen en ons een pull-verzoek sturen. </p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox notranslate"><var>var new_array = arr</var>.map(function <var>callback(currentValue[, index[, array]]) { - </var>// Return element for new_array<var> -}</var>[, <var>thisArg</var>])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>callback</code></dt> - <dd>Functie die een element voor de nieuwe Array produceert en de volgende argumenten aanvaardt: - <dl> - <dt></dt> - <dt><code>currentValue</code></dt> - <dd>Het huidige te verwerken element uit de array.</dd> - <dt><code>index</code>{{optional_inline}}</dt> - <dd>De index van het huidige te verwerken element in die array.</dd> - <dt><code>array</code>{{optional_inline}}</dt> - <dd>De array waarop <code>map</code> werd opgeroepen.</dd> - </dl> - </dd> - <dt><code>thisArg</code>{{optional_inline}}</dt> - <dd>Waarde die moet gebruikt worden voor <code>this</code> bij het uitvoeren van <code>callback</code>.</dd> -</dl> - -<h3 id="Return_value">Return value</h3> - -<p>Een nieuwe array waarbij elk element het resultaat is van het oproepen van de functie op het overeenkomstige element uit de originele array.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p><code>map</code> roept de meegegeven <code>callback</code> functie <strong>één keer op voor elk element</strong> in een array, in volgorde, en maakt een nieuwe array met de resultaten. <code>callback</code> wordt enkel opgeroepen voor indices van de array die een waarde hebben, inclusief <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a>. Het wordt niet opgeroepen voor element die niet (meer) in de array zitten (indices die nog nooit gezet zijn, die werden verwijderd of die nog nooit een waarde hebben gekregen).</p> - -<p>Aangezien <code>map</code> een nieuwe array aanmaakt, heeft het geen zin deze methode aan te roepen als je de geretourneerde array niet gebruikt; gebruik dan eerder <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach"><code>forEach</code></a> of <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of"><code>for-of</code></a>. Gebruik <code>map</code> niet als: A) je de geretourneerde array niet gebruikt, en/of B) de <code>callback</code> functie geen waarde retourneert.</p> - -<p><code>callback</code> wordt aangeroepen met drie argumenten: de waarde van het element, de index van het element en het Array object zelf dat wordt doorlopen.</p> - -<p>Als een <code>thisArg</code> parameter wordt meegegeven aan <code>map</code>, zal het gebruikt worden als <code>this</code> waarde voor de <code>callback</code> functie. Indien niet, wordt {{jsxref("undefined")}} gebruikt als zijn <code>this</code> waarde. De <code>this</code> waarde zoals <code>callback</code> ze uiteindelijk waarneemt, wordt bepaald volgens <a href="/en-US/docs/Web/JavaScript/Reference/Operators/this">de gewone regels voor het bepalen van <code>this</code> zoals waargenomen door een functie</a>.</p> - -<p><code>map</code> wijzigt de array waarop het wordt aangeroepen niet (ofschoon <code>callback</code>, indien aangeroepen, dat wél kan doen).</p> - -<p>Het aantal elementen dat wordt verwerkt door <code>map</code> wordt bepaald vooraleer de eerste aanroep van <code>callback</code> plaatsvindt. Elementen die worden toegevoegd aan de array nadat de aanroep van <code>map</code> is gebeurd zullen door <code>callback</code> niet worden behandeld. Als bestaande elementen van de array worden gewijzigd, dan zijn de waarden die worden doorgegeven aan <code>callback</code> de waarden op het moment dat <code>map</code> ze beschouwt. Elementen die worden verwijderd na het aanroepen van <code>map</code> en vóór ze werden beschouwd worden niet verwerkt.<br> - <br> - Voor de indices waarop de originele array lege plaatsen bevat, zal ook de resulterende array lege plaatsen bevatten.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Een_array_van_getallen_mappen_op_een_array_van_vierkantswortels">Een array van getallen mappen op een array van vierkantswortels</h3> - -<p>De volgende code neemt een array van getallen en creëert een nieuwe array die de vierkantswortels van die getallen bevat.</p> - -<pre class="brush: js notranslate">var getallen = [1, 4, 9]; -var vierkantsWortels = getallen.map(function(getal) { -return Math.sqrt(getal) -}); -// vierkantsWortels is nu [1, 2, 3] -// getallen is nog steeds [1, 4, 9] -</pre> - -<h3 id="Gebruik_van_map_om_objecten_te_herformateren_in_een_array">Gebruik van map om objecten te herformateren in een array</h3> - -<p>De volgende code neemt een array van objecten en creëert een nieuwe array die de geherformatteerde objecten bevat.</p> - -<pre class="brush: js notranslate">var kvArray = [{key: 1, value: 10}, - {key: 2, value: 20}, - {key: 3, value: 30}]; - -var reformattedArray = kvArray.map(obj =>{ - var rObj = {}; - rObj[obj.key] = obj.value; - return rObj; -}); -// reformattedArray is now [{1: 10}, {2: 20}, {3: 30}], - -// kvArray is still: -// [{key: 1, value: 10}, -// {key: 2, value: 20}, -// {key: 3, value: 30}] -</pre> - -<h3 id="Mapping_an_array_of_numbers_using_a_function_containing_an_argument">Mapping an array of numbers using a function containing an argument</h3> - -<p>The following code shows how map works when a function requiring one argument is used with it. The argument will automatically be assigned from each element of the array as map loops through the original array.</p> - -<pre class="brush: js notranslate">var numbers = [1, 4, 9]; -var doubles = numbers.map(function(num) { - return num * 2; -}); - -// doubles is now [2, 8, 18] -// numbers is still [1, 4, 9] -</pre> - -<h3 id="Using_map_generically">Using <code>map</code> generically</h3> - -<p>This example shows how to use map on a {{jsxref("String")}} to get an array of bytes in the ASCII encoding representing the character values:</p> - -<pre class="brush: js notranslate">var map = Array.prototype.map; -var a = map.call('Hello World', function(x) { - return x.charCodeAt(0); -}); -// a now equals [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100] -</pre> - -<h3 id="Using_map_generically_querySelectorAll">Using <code>map</code> generically <code>querySelectorAll</code></h3> - -<p>This example shows how to iterate through a collection of objects collected by <code>querySelectorAll</code>. This is because <code>querySelectorAll</code> returns a <strong><em>NodeList</em> </strong>which is a collection of objects.<br> - In this case we return all the selected options' values on the screen:</p> - -<pre class="brush: js notranslate">var elems = document.querySelectorAll('select option:checked'); -var values = Array.prototype.map.call(elems, function(obj) { - return obj.value; -}); -</pre> - -<p>Easier way would be using {{jsxref("Array.from()")}} method.</p> - -<h3 id="Tricky_use_case">Tricky use case</h3> - -<p><a href="http://www.wirfs-brock.com/allen/posts/166">(inspired by this blog post)</a></p> - -<p>It is common to use the callback with one argument (the element being traversed). Certain functions are also commonly used with one argument, even though they take additional optional arguments. These habits may lead to confusing behaviors.</p> - -<pre class="brush: js notranslate" dir="rtl">// Consider: -['1', '2', '3'].map(parseInt); -// While one could expect [1, 2, 3] -// The actual result is [1, NaN, NaN] - -// parseInt is often used with one argument, but takes two. -// The first is an expression and the second is the radix. -// To the callback function, Array.prototype.map passes 3 arguments: -// the element, the index, the array -// The third argument is ignored by parseInt, but not the second one, -// hence the possible confusion. See the blog post for more details -// If the link doesn't work -// here is concise example of the iteration steps: -// parseInt(string, radix) -> map(parseInt(value, index)) -// first iteration (index is 0): parseInt('1', 0) // results in parseInt('1', 0) -> 1 -// second iteration (index is 1): parseInt('2', 1) // results in parseInt('2', 1) -> NaN -// third iteration (index is 2): parseInt('3', 2) // results in parseInt('3', 2) -> NaN - -function returnInt(element) { - return parseInt(element, 10); -} - -['1', '2', '3'].map(returnInt); // [1, 2, 3] -// Actual result is an array of numbers (as expected) - -// Same as above, but using the concise arrow function syntax -['1', '2', '3'].map( str => parseInt(str) ); - -// A simpler way to achieve the above, while avoiding the "gotcha": -['1', '2', '3'].map(Number); // [1, 2, 3] -// but unlike `parseInt` will also return a float or (resolved) exponential notation: -['1.1', '2.2e2', '3e300'].map(Number); // [1.1, 220, 3e+300] -</pre> - -<p>One alternative output of the map method being called with parseInt as a parameter runs as follows:</p> - -<pre class="brush: js notranslate">var xs = ['10', '10', '10']; - -xs = xs.map(parseInt); - -console.log(xs); -// Actual result of 10,NaN,2 may be unexpected based on the above description.</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p><code>map</code> was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code>map</code> in implementations which do not natively support it. This algorithm is exactly the one specified in ECMA-262, 5th edition, assuming {{jsxref("Object")}}, {{jsxref("TypeError")}}, and {{jsxref("Array")}} have their original values and that <code>callback.call</code> evaluates to the original value of <code>{{jsxref("Function.prototype.call")}}</code>.</p> - -<pre class="brush: js notranslate">// Production steps of ECMA-262, Edition 5, 15.4.4.19 -// Reference: http://es5.github.io/#x15.4.4.19 -if (!Array.prototype.map) { - - Array.prototype.map = function(callback/*, thisArg*/) { - - var T, A, k; - - if (this == null) { - throw new TypeError('this is null or not defined'); - } - - // 1. Let O be the result of calling ToObject passing the |this| - // value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get internal - // method of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = O.length >>> 0; - - // 4. If IsCallable(callback) is false, throw a TypeError exception. - // See: http://es5.github.com/#x9.11 - if (typeof callback !== 'function') { - throw new TypeError(callback + ' is not a function'); - } - - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - if (arguments.length > 1) { - T = arguments[1]; - } - - // 6. Let A be a new array created as if by the expression new Array(len) - // where Array is the standard built-in constructor with that name and - // len is the value of len. - A = new Array(len); - - // 7. Let k be 0 - k = 0; - - // 8. Repeat, while k < len - while (k < len) { - - var kValue, mappedValue; - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal - // method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal - // method of O with argument Pk. - kValue = O[k]; - - // ii. Let mappedValue be the result of calling the Call internal - // method of callback with T as the this value and argument - // list containing kValue, k, and O. - mappedValue = callback.call(T, kValue, k, O); - - // iii. Call the DefineOwnProperty internal method of A with arguments - // Pk, Property Descriptor - // { Value: mappedValue, - // Writable: true, - // Enumerable: true, - // Configurable: true }, - // and false. - - // In browsers that support Object.defineProperty, use the following: - // Object.defineProperty(A, k, { - // value: mappedValue, - // writable: true, - // enumerable: true, - // configurable: true - // }); - - // For best browser support, use the following: - A[k] = mappedValue; - } - // d. Increase k by 1. - k++; - } - - // 9. return A - return A; - }; -} -</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('ES5.1', '#sec-15.4.4.19', 'Array.prototype.map')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Initial definition. Implemented in JavaScript 1.6.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.map', 'Array.prototype.map')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.map', 'Array.prototype.map')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div> -<div class="hidden">De compatibiliteitstabel op deze pagina wordt gegenereerd op basis van gestructureerde gegevens. Als u wilt bijdragen aan de gegevens, kijk dan op <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> en stuur ons een pull-aanvraag.</div> - -<p>{{Compat("javascript.builtins.Array.map")}}</p> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li>{{jsxref("Map")}} object</li> - <li>{{jsxref("Array.from()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/push/index.html b/files/nl/web/javascript/reference/global_objects/array/push/index.html deleted file mode 100644 index db5fe6e5b2..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/push/index.html +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: Array.prototype.push() -slug: Web/JavaScript/Reference/Global_Objects/Array/push -tags: - - Array - - JavaScript - - Method - - Prototype - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/Array/push ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>push()</strong></code> methode voegt een of meerdere elementen toe aan het einde van een array en geeft de nieuwe lengte van de array terug.</p> - -<h2 id="Syntaxis">Syntaxis</h2> - -<pre class="syntaxbox"><code><var>arr</var>.push(<var>element1</var>, ..., <var>elementN</var>)</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>element<em>N</em></code></dt> - <dd>De elementen om toe te voegen aan het einde van de array.</dd> -</dl> - -<h3 id="Geeft_terug">Geeft terug</h3> - -<p>De nieuwe {{jsxref("Array.length", "length")}} eigenschap van het object waarop deze methode is aangeroepen.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De <code>push</code> methode voegt waardes toe aan een array.</p> - -<p><code>push</code> is opzettelijk generiek. Deze methode kan gebruikt worden met {{jsxref("Function.call", "call()")}} of {{jsxref("Function.apply", "apply()")}} op objecten welke op arrays lijken. De <code>push</code> methode rekent op een <code>length</code> eigenschap om te kunnen weten waar de nieuwe waardes toegevoegd moeten worden. Als de <code>length</code> eigenschap niet kan worden omgezet naar een getal, wordt de gebruikte index 0. Dit geldt ook wanneer <code>length</code> niet bestaat, in welk geval <code>length</code> gemaakt wordt, ook met waarde 0.</p> - -<p>De enige native, array-achtige objecten zijn {{jsxref("Global_Objects/String", "strings", "", 1)}}, hoewel zij niet geschikt zijn voor het gebruik van deze methode, omdat strings onveranderlijk zijn.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Elementen_aan_een_array_toevoegen">Elementen aan een array toevoegen</h3> - -<p>De volgende code maakt de <code>sports</code> array met twee elementen en voegt twee elementen er aan toe. De <code>total</code> variabele bevat de nieuwe lengte van de array.</p> - -<pre class="brush: js">var sports = ['soccer', 'baseball']; -var total = sports.push('football', 'swimming'); - -console.log(sports); // ['soccer', 'baseball', 'football', 'swimming'] -console.log(total); // 4 -</pre> - -<h3 id="Twee_arrays_samenvoegen">Twee arrays samenvoegen</h3> - -<p>Dit voorbeeld gebruikt {{jsxref("Function.apply", "apply()")}} om alle elementen van een tweede array te pushen.</p> - -<pre class="brush: js">var vegetables = ['parsnip', 'potato']; -var moreVegs = ['celery', 'beetroot']; - -// De tweede array in de eerste voegen -// Gelijk aan vegetables.push('celery', 'beetroot'); -Array.prototype.push.apply(vegetables, moreVegs); - -console.log(vegetables); // ['parsnip', 'potato', 'celery', 'beetroot'] -</pre> - -<h3 id="Een_object_gebruiken_op_een_array-achtige_manier">Een object gebruiken op een array-achtige manier</h3> - -<p>Zoals hierboven gezegd is <code>push</code> opzettelijk generiek, wat we in ons voordeel kunnen gebruiken. <code>Array.prototype.push</code> werkt ook op objecten, zoals dit voorbeeld laat zien. We maken geen array om een verzameling objecten op te slaan. We slaan de verzameling op in het object zelf en gebruiken <code>call</code> op <code>Array.prototype.push</code> om de methode te laten denken dat we te maken hebben met een array en het werkt. Dit is te danken aan de manier waarop JavaScript toestaat om de context van uitvoer te bepalen.</p> - -<pre class="brush: js">var obj = { - length: 0, - - addElem: function addElem (elem) { - // obj.length wordt automatisch verhoogd elke keer dat een element wordt toegevoegd. - [].push.call(this, elem); - } -}; - -// Lege objecten toevoegen om het idee te laten zien -obj.addElem({}); -obj.addElem({}); -console.log(obj.length); -// → 2 -</pre> - -<p>Hoewel <code>obj</code> geen array is zorgt de <code>push</code> methode er voor dat <code>obj</code>'s <code>length</code> eigenschap wordt verhoogd, zoals ook zou gebeuren als dit gedaan zou worden op een echte array.</p> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Eerste definitie. Geïmplementeerd in JavaScript 1.2.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.7', 'Array.prototype.push')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.push', 'Array.prototype.push')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.push', 'Array.prototype.push')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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("1.0")}}</td> - <td>{{CompatGeckoDesktop("1.7")}}</td> - <td>{{CompatIE("5.5")}}</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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.pop()")}}</li> - <li>{{jsxref("Array.prototype.shift()")}}</li> - <li>{{jsxref("Array.prototype.unshift()")}}</li> - <li>{{jsxref("Array.prototype.concat()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/shift/index.html b/files/nl/web/javascript/reference/global_objects/array/shift/index.html deleted file mode 100644 index 7187acb853..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/shift/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: Array.prototype.shift() -slug: Web/JavaScript/Reference/Global_Objects/Array/shift -translation_of: Web/JavaScript/Reference/Global_Objects/Array/shift ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>shift()</strong></code> methode verwijdert het <strong>eerste</strong> element van de array en geeft het element terug als resultaat. Deze methode wijzigt de lengte van de array.</p> - -<pre class="brush: js">var a = [1, 2, 3]; -var b = a.shift(); - -console.log(a); // [2, 3] -console.log(b); // 1 -</pre> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>arr</var>.shift()</pre> - -<h3 id="Return_value">Return value</h3> - -<p>Het verwijderde element van de array; {{jsxref("undefined")}} als de array leeg is.</p> - -<h2 id="Description">Description</h2> - -<p>De <code>shift</code> methode verwijdert het element met index nul en schuift de volgende waarden met hogere index, 1 positie terug. Het verwijderde element is het resultaat. Als de {{jsxref("Array.length", "length")}} property 0 is, is het resultaat {{jsxref("undefined")}} .</p> - -<p><code>shift</code> is bewust generiek; deze methode kan worden {{jsxref("Function.call", "aangeroepen", "", 1)}} of {{jsxref("Function.apply", "toegepast", "", 1)}} op op array gelijkende objecten. Objects zonder <code>length</code> property, die de laatste van een serie van opeenvolgende, op nul gebaseerde numerische properties reflecteren, kunnen zich op een niet betekenisvolle manier gedragen.</p> - -<h2 id="Examples">Examples</h2> - -<h3 id="Removing_an_element_from_an_array">Removing an element from an array</h3> - -<p>De volgend code toont de <code>myFish</code> array voor en na het verwijderen van het eerste element. Het toont ook het verwijderde element:</p> - -<pre class="brush: js">var myFish = ['angel', 'clown', 'mandarin', 'surgeon']; - -console.log('myFish before:', JSON.stringify(myFish)); -// myFish before: ['angel', 'clown', 'mandarin', 'surgeon'] - -var shifted = myFish.shift(); - -console.log('myFish after:', myFish); -// myFish after: ['clown', 'mandarin', 'surgeon'] - -console.log('Removed this element:', shifted); -// Removed this element: angel -</pre> - -<h3 id="Using_shift()_method_in_while_loop">Using shift() method in while loop</h3> - -<p>De shift() methode wordt vaak gebruikt als een conditie in een while lus. In het volgende voorbeeld verwijdert elke iteratie het volgende element van de array totdat ze leeg is:</p> - -<pre class="brush: js">var names = ["Andrew", "Edward", "Paul", "Chris" ,"John"]; - -while( (i = names.shift()) !== undefined ) { - console.log(i); -} -// Andrew, Edward, Paul, Chris, John -</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.2.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.9', 'Array.prototype.shift')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.shift', 'Array.prototype.shift')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.shift', 'Array.prototype.shift')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div> - - -<p>{{Compat("javascript.builtins.Array.shift")}}</p> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("Array.prototype.push()")}}</li> - <li>{{jsxref("Array.prototype.pop()")}}</li> - <li>{{jsxref("Array.prototype.unshift()")}}</li> - <li>{{jsxref("Array.prototype.concat()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/slice/index.html b/files/nl/web/javascript/reference/global_objects/array/slice/index.html deleted file mode 100644 index d3dcaf0acb..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/slice/index.html +++ /dev/null @@ -1,269 +0,0 @@ ---- -title: Array.prototype.slice() -slug: Web/JavaScript/Reference/Global_Objects/Array/slice -translation_of: Web/JavaScript/Reference/Global_Objects/Array/slice ---- -<p>{{JSRef}}<br> - De <code><strong>slice()</strong></code> method geeft een oppervlakkige kopie van een gedeelte van een array terug in een nieuwe array.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>arr</var>.slice([<var>begin</var>[, <var>end</var>]])</code></pre> - -<h2 id="Parameters">Parameters</h2> - -<dl> - <dt><code>begin</code></dt> - <dd>Bij nul beginnende index (zero-based), van waaruit de extractie begint.</dd> - <dd>Bij een negatieve index, geeft <code>begin</code> het aantal plaatsen (offset) tot aan het einde van de reeks. <code>slice(-2)</code> extraheert de laatste twee elementen van de sequentie.</dd> - <dd>Indien <code>begin</code> niet gedefinieerd is, of gelijkwaardig is aan undefined, dan begint <code>slice</code> bij index <code>0</code>.</dd> - <dt><code>end</code></dt> - <dd>Bij nul beginnende index waarop de extractie gestopt wordt. <code>slice</code> extraheert tot aan, maar exclusief <code>end</code>.</dd> - <dd><code>slice(1,4)</code> extraheert het tweede element tot het vierde element (elementen met index 1, 2, en 3).</dd> - <dd>Als negatieve index, geeft <code>end</code> een afstand (offset) aan tot het einde van de reeks. <code>slice(2,-1)</code> extraheert het derde element tot het op twee na laatse element in de sequentie.</dd> - <dd>Indien <code>end</code> wordt weggelaten, dan zal <code>slice</code> tot het einde van de reeks toe extraheren (<code>arr.length</code>)<code>.</code></dd> -</dl> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p><code>slice</code> verandert niet. Het retourneert een oppervlakkige kopie van elementen, ten opzichte van de oorspronkelijke array. Elementen van het origineel, worden als volgt gekopieerd en geretourneerd:</p> - -<ul> - <li>Voor object referenties (en dus niet het eigenlijke object), kopieert <code>slice</code> object referenties naar een nieuwe array. Zowel het origineel als ook de nieuwe array verwijzen naar hetzelfde object. Indien een object, waarnaar verwezen wordt, verandert, dan zullen de wijzigingen zowel in de nieuwe als bestaande array zichtbaar worden.</li> - <li>Voor strings en getallen (geen {{jsxref("String")}} en {{jsxref("Number")}} objects), kopieert <code>slice</code> strings en getallen naar de nieuwe array. Veranderingen aan een string of getal in de ene array zal de andere array niet beinvloeden.</li> -</ul> - -<p>Indien een nieuw element aan de ene array wordt toegevoegd, dan blijft de andere array onaangeroerd.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Geeft_een_gedeelte_van_een_bestaande_array">Geeft een gedeelte van een bestaande array</h3> - -<pre class="brush: js">var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']; -var citrus = fruits.slice(1, 3); - -// fruits contains ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango'] -// citrus contains ['Orange','Lemon'] -</pre> - -<h3 id="Gebruik_slice">Gebruik <code>slice</code></h3> - -<p>In het volgende voorbeeld, maakt <code>slice</code> een nieuwe array aan, <code>newCar</code>, uit <code>myCar</code>. Beide hebben een referentie aan het object <code>myHonda</code>. Wanneer de kleur van <code>myHonda</code> wordt gewijzigd, dan hebben beide arrays deze wisseling ondergaan.</p> - -<pre class="brush: js">// Using slice, create newCar from myCar. -var myHonda = { color: 'red', wheels: 4, engine: { cylinders: 4, size: 2.2 } }; -var myCar = [myHonda, 2, 'cherry condition', 'purchased 1997']; -var newCar = myCar.slice(0, 2); - -// Display the values of myCar, newCar, and the color of myHonda -// referenced from both arrays. -console.log('myCar = ' + myCar.toSource()); -console.log('newCar = ' + newCar.toSource()); -console.log('myCar[0].color = ' + myCar[0].color); -console.log('newCar[0].color = ' + newCar[0].color); - -// Change the color of myHonda. -myHonda.color = 'purple'; -console.log('The new color of my Honda is ' + myHonda.color); - -// Display the color of myHonda referenced from both arrays. -console.log('myCar[0].color = ' + myCar[0].color); -console.log('newCar[0].color = ' + newCar[0].color); -</pre> - -<p>Het script verwerkt dit als volgt:</p> - -<pre class="brush: js">myCar = [{color:'red', wheels:4, engine:{cylinders:4, size:2.2}}, 2, - 'cherry condition', 'purchased 1997'] -newCar = [{color:'red', wheels:4, engine:{cylinders:4, size:2.2}}, 2] -myCar[0].color = red -newCar[0].color = red -The new color of my Honda is purple -myCar[0].color = purple -newCar[0].color = purple -</pre> - -<h2 id="Array-achtige_objecten">Array-achtige objecten</h2> - -<p><code>De slice</code> method kan ook gebruikt worden om Array-like objects / collections om te zetten in een nieuwe Array. Je hoeft dan alleen de methode op zich aan het object te binden. De {{jsxref("Functions/arguments", "arguments")}} binnen een functie is een voorbeeld van een 'array-like object'.</p> - -<pre class="brush: js">function list() { - return Array.prototype.slice.call(arguments); -} - -var list1 = list(1, 2, 3); // [1, 2, 3] -</pre> - -<p>Binding kan worden verkregen met de .<code>call</code> functie of {{jsxref("Function.prototype")}} en dit kan ook via reductie door gebruik te maken van <code>[].slice.call(arguments)</code> in plaats van de <code>Array.prototype.slice.call</code>. Hoe dan ook, het kan worden vereenvoudigd met {{jsxref("Function.prototype.bind", "bind")}}.</p> - -<pre class="brush: js">var unboundSlice = Array.prototype.slice; -var slice = Function.prototype.call.bind(unboundSlice); - -function list() { - return slice(arguments); -} - -var list1 = list(1, 2, 3); // [1, 2, 3] -</pre> - -<h2 id="Cross-browser_gedrag_in_de_hand_werken">Cross-browser gedrag in de hand werken</h2> - -<p>Host objecten zoals DOM-objecten, zijn volgens de spec niet verplicht zich te gedragen zoals in een Mozilla browser, wanneer een omzetting plaatsvindt volgens de Array.prototype.slice methode. IE browsers voor versie 9 doen dit bijvoorbeeld niet. De huidige browser versies van IE, Mozilla, Chrome, Safari en Opera ondersteunen het eerder beschreven oppervlakkige kopie ('shallow copy') gedrag en het is daarmee de-facto het standaard gedrag.<br> - Door onderstaande code vooraf te laten gaan aan de eigen code, kun je het toch mogelijk maken dat een browser zich zoals je zou verwachten gaat gedragen en er verder geen afwijkende browser specifieke code gebruikt hoeft te worden.</p> - -<pre class="brush: js">/** - * Shim for "fixing" IE's lack of support (IE < 9) for applying slice - * on host objects like NamedNodeMap, NodeList, and HTMLCollection - * (technically, since host objects have been implementation-dependent, - * at least before ES6, IE hasn't needed to work this way). - * Also works on strings, fixes IE < 9 to allow an explicit undefined - * for the 2nd argument (as in Firefox), and prevents errors when - * called on other DOM objects. - */ -(function () { - 'use strict'; - var _slice = Array.prototype.slice; - - try { - // Can't be used with DOM elements in IE < 9 - _slice.call(document.documentElement); - } catch (e) { // Fails in IE < 9 - // This will work for genuine arrays, array-like objects, - // NamedNodeMap (attributes, entities, notations), - // NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes), - // and will not fail on other DOM objects (as do DOM elements in IE < 9) - Array.prototype.slice = function(begin, end) { - // IE < 9 gets unhappy with an undefined end argument - end = (typeof end !== 'undefined') ? end : this.length; - - // For native Array objects, we use the native slice function - if (Object.prototype.toString.call(this) === '[object Array]'){ - return _slice.call(this, begin, end); - } - - // For array like object we handle it ourselves. - var i, cloned = [], - size, len = this.length; - - // Handle negative value for "begin" - var start = begin || 0; - start = (start >= 0) ? start : Math.max(0, len + start); - - // Handle negative value for "end" - var upTo = (typeof end == 'number') ? Math.min(end, len) : len; - if (end < 0) { - upTo = len + end; - } - - // Actual expected size of the slice - size = upTo - start; - - if (size > 0) { - cloned = new Array(size); - if (this.charAt) { - for (i = 0; i < size; i++) { - cloned[i] = this.charAt(start + i); - } - } else { - for (i = 0; i < size; i++) { - cloned[i] = this[start + i]; - } - } - } - - return cloned; - }; - } -}()); -</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.2.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.10', 'Array.prototype.slice')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.slice', 'Array.prototype.slice')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.slice', 'Array.prototype.slice')}}</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("1.0")}}</td> - <td>{{CompatGeckoDesktop("1.7")}}</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("Function.prototype.call()")}}</li> - <li>{{jsxref("Function.prototype.bind()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/array/splice/index.html b/files/nl/web/javascript/reference/global_objects/array/splice/index.html deleted file mode 100644 index c373091346..0000000000 --- a/files/nl/web/javascript/reference/global_objects/array/splice/index.html +++ /dev/null @@ -1,177 +0,0 @@ ---- -title: Array.prototype.splice() -slug: Web/JavaScript/Reference/Global_Objects/Array/splice -translation_of: Web/JavaScript/Reference/Global_Objects/Array/splice ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>splice()</strong></code>-methode past de inhoud van een array aan door bestaande elementen te verwijderen en/of nieuwe elementen toe te voegen.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>array</var>.splice(<var>start[</var>, <var>deleteCount</var>[, <var>item1</var>[, <var>item2</var>[, ...]]]]) -</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>start</code></dt> - <dd>Positie vanwaar de array dient te worden veranderd (met eerste element op 0). Indien groter dan de lengte van de array zal de <code>start </code>worden omgezet naar de lengte van de array. Indien negatief begint hij het absolute aantal vanaf het einde van de array.</dd> - <dt><code>deleteCount</code></dt> - <dd>Een getal dat aanduidt hoeveel elementen moeten worden verwijderd. Indien 0 worden er geen elementen verwijderd. In dit geval moet minstens één toe te voegen element worden meegeven. Als de <code>deleteCount </code>groter is dan het overige aantal elementen in de array (beginnend bij de startwaarde) worden al deze overige elementen verwijderd.</dd> - <dd>Indien de <code>deleteCount </code>niet wordt meegegeven, wordt deze als volgt berekend: (<code>arr.length - start</code>)<code>. </code>Dit heeft als resultaat dat alle elementen na de startwaarde worden verwijderd.</dd> - <dt><code>item1, item2, <em>...</em></code></dt> - <dd>De elementen die in de array moeten worden toegevoegd, beginnend op de positie van de <code>start </code>-waarde. Indien niet meegegeven zullen er enkel elementen uit de array verwijderd worden.</dd> -</dl> - -<h3 id="Retourwaarde">Retourwaarde</h3> - -<p>Een array die de verwijderde items bevat. Wanneer slechts één element is verwijderd, wordt er een array teruggegeven met één element. Wanneer er geen elementen zijn verwijderd, wordt een lege array teruggegeven.</p> - -<h2 id="Omschrijving">Omschrijving</h2> - -<p>Wanneer een ander aantal elementen wordt ingevoegd dan het aantal elementen dat wordt verwijderd, zal de array een andere lengte hebben na afloop van de aanroep.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Gebruik_van_splice()">Gebruik van <code>splice()</code></h3> - -<p>The following script illustrates the use of <code>splice()</code>:</p> - -<pre class="brush: js">var myFish = ['angel', 'clown', 'mandarin', 'surgeon']; - -// removes 0 elements from index 2, and inserts 'drum' -var removed = myFish.splice(2, 0, 'drum'); -// myFish is ['angel', 'clown', 'drum', 'mandarin', 'surgeon'] -// removed is [], no elements removed - -// myFish is ['angel', 'clown', 'drum', 'mandarin', 'surgeon'] -// removes 1 element from index 3 -removed = myFish.splice(3, 1); -// myFish is ['angel', 'clown', 'drum', 'surgeon'] -// removed is ['mandarin'] - -// myFish is ['angel', 'clown', 'drum', 'surgeon'] -// removes 1 element from index 2, and inserts 'trumpet' -removed = myFish.splice(2, 1, 'trumpet'); -// myFish is ['angel', 'clown', 'trumpet', 'surgeon'] -// removed is ['drum'] - -// myFish is ['angel', 'clown', 'trumpet', 'surgeon'] -// removes 2 elements from index 0, and inserts 'parrot', 'anemone' and 'blue' -removed = myFish.splice(0, 2, 'parrot', 'anemone', 'blue'); -// myFish is ['parrot', 'anemone', 'blue', 'trumpet', 'surgeon'] -// removed is ['angel', 'clown'] - -// myFish is ['parrot', 'anemone', 'blue', 'trumpet', 'surgeon'] -// removes 2 elements from index 2 -removed = myFish.splice(myFish.length -3, 2); -// myFish is ['parrot', 'anemone', 'surgeon'] -// removed is ['blue', 'trumpet'] - -const myFish = ['parrot', 'anemone', 'blue', 'trumpet', 'surgeon']; -// removes 3 elements starting at index 2 -const removed = myFish.splice(2); -// myFish is ['parrot', 'anemone'] -// removed is ['blue', 'trumpet', 'surgeon'] -</pre> - -<h2 id="Specificaties">Specificaties</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.2.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.4.12', 'Array.prototype.splice')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype.splice', 'Array.prototype.splice')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype.splice', 'Array.prototype.splice')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser-compatibiliteit">Browser-compatibiliteit</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("1.0")}}</td> - <td>{{CompatGeckoDesktop("1.7")}}</td> - <td>{{CompatIE("5.5")}}</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="Compatibiliteit_met_oudere_versies">Compatibiliteit met oudere versies</h2> - -<p>In JavaScript 1.2 <code>retourneert de splice()</code>-methode het verwijderde element, wanneer slechts één element is verwijderd (<code>deleteCount</code> parameter is 1); in andere gevallen retourneert de methode een array met de verwijderde elementen.</p> - -<div class="note"> -<p><strong>Ter info:</strong> De laatste browser die gebruik maakte van JavaScript 1.2 was Netscape Navigator 4, dus er kan altijd worden verwacht dat <code>splice()</code> altijd een array retourneert. Dit is het geval wanneer een JavaScript-object een <code>length</code>-property heeft en een <code>splice()</code>-method. {{domxref("console.log()")}} werkt op dit object als op een Array-acthig object. Het object controleren met <code>instanceof Array</code> retourneert <code>false.</code></p> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Array.prototype.push()", "push()")}} / {{jsxref("Array.prototype.pop()", "pop()")}} — voeg elementen toe/verwijder elementen vanaf het eind van de array</li> - <li>{{jsxref("Array.prototype.unshift()", "unshift()")}} / {{jsxref("Array.prototype.shift()", "shift()")}} — voeg elementen toe/verwijder elementen vanaf het begin van de array</li> - <li>{{jsxref("Array.prototype.concat()", "concat()")}} — retourneer een nieuw array samengesteld uit waarden van dit array en andere arrays of waarden</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/date/index.html b/files/nl/web/javascript/reference/global_objects/date/index.html deleted file mode 100644 index 98895e0fe3..0000000000 --- a/files/nl/web/javascript/reference/global_objects/date/index.html +++ /dev/null @@ -1,266 +0,0 @@ ---- -title: Date -slug: Web/JavaScript/Reference/Global_Objects/Date -tags: - - Datum - - JavaScript - - Referentie -translation_of: Web/JavaScript/Reference/Global_Objects/Date ---- -<div>{{JSRef}}</div> - -<p>Creëert een JavaScript <strong><code>Date</code></strong> instantie die een enkel punt in tijd voorstelt. <code>Date</code> objecten zijn gebaseerd op een tijdwaarde die gelijk staat aan het aantal milliseconden sinds 1 Januari, 1970 UTC.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox">new Date(); -new Date(<var>value</var>); -new Date(<var>dateString</var>); -new Date(<var>year</var>, <var>month</var>[, <var>day</var>[, <var>hour</var>[, <var>minutes</var>[, <var>seconds</var>[, <var>milliseconds</var>]]]]]); -</pre> - -<div class="note"> -<p><strong>NB:</strong> JavaScript <code>Date</code> kan enkel worden geïnstantieerd door JavaScript <code>Date</code> als een constructor aan te roepen: het aanroepen als een gewone functie (bijv. zonder de {{jsxref("Operators/new", "new")}} operator) zal een string terug geven in plaats van een <code>Date</code> object; anders dan andere JavaScript object types, hebben JavaScript <code>Date</code> objecten geen letterlijke syntax.</p> -</div> - -<h3 id="Parameters">Parameters</h3> - -<div class="note"> -<p><strong>NB:</strong> Indien <code>Date</code> wordt aangeroepen als een constructor met meer dan een argument, als waarden groter zijn dan hun logische reeks (bij. 13 wordt gegeven als waarde voor de maand of 70 voor als waarde voor de minuut), wordt de naastgelegen waarde aangepast. Bijvoorbeeld <code>new Date(2013, 13, 1)</code> staat gelijk aan <code>new Date(2014, 1, 1)</code>, beide creëren een datum voor <code>2014-02-01</code> (let er op dat de maand vanaf 0 telt). Dit geldt ook voor andere waarden: <code>new Date(2013, 2, 1, 0, 70)</code> is gelijk aan <code>new Date(2013, 2, 1, 1, 10)</code> en beide creëren een datum voor <code>2013-03-01T01:10:00</code>.</p> -</div> - -<div class="note"> -<p><strong>NB:</strong> Waar <code>Date</code> wordt aangeroepen als een constructor met meer dan een argument, staan de opgegeven argumenten voor lokale tijd. Als UTC gewenst is, gebruik dan <code>new Date({{jsxref("Date.UTC()", "Date.UTC(...)")}})</code> met dezelfde argumenten.</p> -</div> - -<dl> - <dt><code>value</code></dt> - <dd>Numerieke waarde die het aantal milliseconden voorstelt vanaf 1 Januari 1970 00:00:00 UTC (Unix Tijdperk; maar hou er rekening mee dat de meeste Unix tijd functies in seconden tellen).</dd> - <dt><code>dateString</code></dt> - <dd>Tekstuele weergave van de datum. De tekst moet een formaat hebben dat wordt herkend door de {{jsxref("Date.parse()")}} methode (<a href="http://tools.ietf.org/html/rfc2822#page-14">IETF-compliant RFC 2822 timestamps</a> en ook een <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15">versie van ISO8601</a>). - <div class="note"> - <p><strong>Note:</strong> Het parsen van datumstrings met de <code>Date</code> constructor (en <code>Date.parse</code>, deze zijn gelijkwaardig) wordt sterk afgeraden door de verschillen en inconsistenties van browsers.</p> - </div> - </dd> - <dt><code>year</code></dt> - <dd>Numerieke voorstelling van het jaar. Waarden van 0 tot 99 komen overeen met de jaren 1900 tot 1999. Zie het {{anch("Two_digit_years_map_to_1900_-_1999", "voorbeeld beneden")}}.</dd> - <dt><code>month</code></dt> - <dd>Numerieke voorstelling van de maand, beginnend met 0 voor januari tot 11 voor december.</dd> - <dt><code>day</code></dt> - <dd>Optioneel. Numerieke voorstelling van de dag van de maand.</dd> - <dt><code>hour</code></dt> - <dd>Optioneel. Numerieke voorstelling van het uur van de dag.</dd> - <dt><code>minute</code></dt> - <dd>Optioneel. Numerieke voorstelling van het minuut segment van een tijd.</dd> - <dt><code>second</code></dt> - <dd>Optioneel. Numerieke voorstelling van het seconde segment van een tijd.</dd> - <dt><code>millisecond</code></dt> - <dd>Optioneel. Numerieke voorstelling van het milliseconde segment van een tijd.</dd> -</dl> - -<h2 id="Omschrijving">Omschrijving</h2> - -<ul> - <li>Als er geen argumenten worden gegeven, zal een JavaScript <code>Date</code> object worden gemaakt volgens de huidige tijd en systeeminstellingen.</li> - <li>Als er ten minste twee argumenten worden gegeven, worden ontbrekende argumenten op 1 gezet (als de dag ontbreekt) of 0 voor alle andere.</li> - <li>De Javascript datum is gebaseerd op een tijdswaarde dat het aantal milliseconden voorstelt sinds 01 Januari, 1970 UTC. Een dag bevat 86,400,000 milliseconden. Het JavaScript <code>Date</code> object heeft een waarde reeks van -100,000,000 dagen tot 100,000,000 dagen relatief aan 01 Januari, 1970 UTC.</li> - <li>Het JavaScript <code>Date</code> object biedt uniform gedrag tussen platformen. De tijdswaarde kan doorgegeven worden tussen systemen om hetzelfde punt in tijd voor te stellen. </li> - <li>Het JavaScript <code>Date</code> object ondersteunt een aantal UTC (universal) functies, evenals lokale tijd functies. UTC, ook bekend als Greenwich Mean Time (GMT), refereert naar de tijd zoals bepaald door de World Time Standard. De lokale tijd is de tijd zoals bekend bij de computer waar JavaScript wordt uitgevoerd.</li> - <li>Het aanroepen van JavaScript <code>Date</code> als een functie (ofwel, zonder de {{jsxref("Operators/new", "new")}} operator) zal een tekstreeks teruggeven die de huidige datum en tijd weergeeft.</li> -</ul> - -<h2 id="Eigenschappen">Eigenschappen</h2> - -<dl> - <dt>{{jsxref("Date.prototype")}}</dt> - <dd>Staat het toe om eigenschappen toe te voegen aan het JavaScript <code>Date</code> object.</dd> - <dt><code>Date.length</code></dt> - <dd>De waarde van <code>Date.length</code> is 7. Dit is het aantal argumenten wat door de constructor wordt verwerkt.</dd> -</dl> - -<h2 id="Methodes">Methodes</h2> - -<dl> - <dt>{{jsxref("Date.now()")}}</dt> - <dd>Geeft de numerieke waarde van de huidige tijd - het aantal milliseconden verlopen sinds 1 Januari 1970 00:00:00 UTC.</dd> - <dt>{{jsxref("Date.parse()")}}</dt> - <dd>Verwerkt een tekstuele representaie van een datum en geeft het aantal milliseconden terug vanaf 1 Januari, 1970, 00:00:00, UTC. - <div class="note"> - <p><strong>Note:</strong> Het parsen van datumstrings met de <code>Date</code> constructor (en <code>Date.parse</code>, deze zijn gelijk) wordt sterk afgeraden door de verschillen en inconsistenties van browsers.</p> - </div> - </dd> - <dt>{{jsxref("Date.UTC()")}}</dt> - <dd>Accepteert de zelfde parameters als de langste vorm van de constructor (ofwel 2 tot 7) en geeft het aantal milliseconden terug vanaf 1 Januari, 1970, 00:00:00 UTC.</dd> -</dl> - -<h2 id="JavaScript_Date_instanties">JavaScript <code>Date</code> instanties</h2> - -<p>Alle <code>Date</code> instanties erven van {{jsxref("Date.prototype")}}. Het prototype object van de <code>Date</code> constructor kan aangepast worden om alle <code>Date</code> instanties te beïnvloeden.</p> - -<h3 id="Date.prototype_Methodes">Date.prototype Methodes</h3> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype', 'Methods')}}</div> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Verschillende_manieren_om_een_Date_object_te_creëeren">Verschillende manieren om een <code>Date</code> object te creëeren</h3> - -<p>De volgende voorbeelden tonen verschillende manieren om Javascript datums te creëren:</p> - -<div class="note"> -<p><strong>Note: </strong>Het parsen van datumstrings met de <code>Date</code> constructor (en <code>Date.parse</code>, deze zijn gelijk) wordt sterk afgeraden vanwege de verschillen en inconsistenties van browsers.</p> -</div> - -<pre class="brush: js">var vandaag = new Date(); -var verjaardag = new Date('December 17, 1995 03:24:00'); -var verjaardag = new Date('1995-12-17T03:24:00'); -var verjaardag = new Date(1995, 11, 17); -var verjaardag = new Date(1995, 11, 17, 3, 24, 0); -</pre> - -<h3 id="Tweegetals_jaren_worden_getransformeerd_tot_1900-1999">Tweegetals jaren worden getransformeerd tot 1900-1999</h3> - -<p>Om datums tussen de jaren 0 en 99 te creëeren en te verkrijgen, horen {{jsxref("Date.prototype.setFullYear()")}} en {{jsxref("Date.prototype.getFullYear()")}} gebruikt te worden.</p> - -<pre class="brush: js">var date = new Date(98, 1); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT) - -// Verouderde methode, 98 wordt hier naar 1998 omgezet -date.setYear(98); // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT) - -date.setFullYear(98); // Sat Feb 01 0098 00:00:00 GMT+0000 (BST) -</pre> - -<h3 id="Verstreken_tijd_berekenen">Verstreken tijd berekenen</h3> - -<p>De volgende voorbeelden tonen hoe het mogelijk is om te bepalen hoeveel tijd, in milliseconden, er is verstreken tussen twee Javascript datums.</p> - -<p>In verband met het de mogelijke verschillen in lengtes van dagen (door de overgangen tussen zomer- en wintertijd), maanden en jaren, kunnen er problemen optreden als wordt geprobeerd verschillen te bepalen die groter zijn dan uren, minuten en seconden. Het wordt aangeraden eerst grondig onderzoek hiernaar te doen, alvorens dit te proberen.</p> - -<pre class="brush: js">// met Date objecten -var start = Date.now(); - -// de gebeurtenis om te meten hoort hier: -doeIetsVoorEenLangePeriode(); -var einde = Date.now(); -var verstreken = einde - start; // verstreken tijd in milliseconden -</pre> - -<pre class="brush: js">// met ingebouwde methodes -var start = new Date(); - -// de gebeurtenis om te meten hoort hier: -doeIetsVoorEenLangePeriode(); -var einde = new Date(); -var verstreken = einde.getTime() - start.getTime(); // verstreken tijd in milliseconden -</pre> - -<pre class="brush: js">// om een functie te testen en de return waarde terug te krijgen -function printVerstrekenTijd(fTest) { - var nStartTijd = Date.now(), - vReturn = fTest(), - nEindTijd = Date.now(); - - console.log('Verstreken tijd: ' + String(nEindTijd - nStartTijd) + ' milliseconden'); - return vReturn; -} - -var jouwFunctieReturn = printVerstrekenTijd(jouwFunctie); -</pre> - -<div class="note"> -<p><strong>NB: </strong>In browsers die ondersteuning bieden voor {{domxref("window.performance", "Web Performance API", "", 1)}}'s hoge resolutie tijdsfunctionaliteiten, kan {{domxref("Performance.now()")}} meer betrouwbare en preciezere metingen opleveren dan {{jsxref("Date.now()")}} kan.</p> -</div> - -<h3 id="Aantal_seconden_sinds_Unix_Epoch">Aantal seconden sinds Unix Epoch</h3> - -<pre><code>var seconden = Math.floor(Date.now() / 1000);</code></pre> - -<p>In dit geval is het belangrijk een geheel getal te retourneren (eenvoudige deling is niet toereikend), waarbij het gaat het aantal feitelijk verstreken seconden (daarom gebruikt deze code {{jsxref("Math.floor()")}} en niet {{jsxref("Math.round()")}}).</p> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Commentaar</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-date-objects', 'Date')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-date-objects', 'Date')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.9', 'Date')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initiële definitie. Geïmplementeerd in JavaScript 1.1.</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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>{{CompatVersionUnknown}} [1]</td> - <td>{{CompatVersionUnknown}} [1]</td> - <td>{{CompatVersionUnknown}} [2]</td> - <td>{{CompatVersionUnknown}} [1]</td> - <td>{{CompatVersionUnknown}} [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>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<p>[1] Some browsers can have issues when parsing dates: <a href="http://dygraphs.com/date-formats.html">3/14/2012 blog from danvk Comparing FF/IE/Chrome on Parsing Date Strings</a></p> - -<p>[2] <a href="https://msdn.microsoft.com/en-us//library/ie/ff743760(v=vs.94).aspx">ISO8601 Date Format is not supported</a> in Internet Explorer 8, and other version can have <a href="http://dygraphs.com/date-formats.html">issues when parsing dates</a></p> diff --git a/files/nl/web/javascript/reference/global_objects/function/apply/index.html b/files/nl/web/javascript/reference/global_objects/function/apply/index.html deleted file mode 100644 index 51428929f1..0000000000 --- a/files/nl/web/javascript/reference/global_objects/function/apply/index.html +++ /dev/null @@ -1,258 +0,0 @@ ---- -title: Function.prototype.apply() -slug: Web/JavaScript/Reference/Global_Objects/Function/apply -translation_of: Web/JavaScript/Reference/Global_Objects/Function/apply ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>apply()</strong></code> methode roept een functie aan met een gegeven <code>this</code> waarde en argumenten gedefineerd als een array (of een <a href="/en-US/docs/Web/JavaScript/Guide/Indexed_collections#Working_with_array-like_objects">array-achtig object</a>).</p> - -<div class="note"> -<p><strong>Let op:</strong> Hoewel de syntax van deze functie vrijwel gelijk is aan die van {{jsxref("Function.call", "call()")}}, is het fundamentele verschil met <code>call()</code> dat deze een <strong>lijst van argumenten</strong> accepteert, terwijl <code>apply()</code> een <strong>enkele array van argumenten</strong> verwacht.</p> -</div> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox notranslate"><var>fun</var>.apply(<var>thisArg, </var>[<var>argsArray</var>])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>thisArg</code></dt> - <dd>De waarde van this die aan de call voor <em>fun</em> wordt meegegeven. Hou er rekening mee dat dit mogelijk niet de waarde is die de methode ziet: Als de methode gedefineerd is in <a href="https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode" title="The documentation about this has not yet been written; please consider contributing!">non-strict mode</a> code, dan zullen <a href="https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/null" title="De waarde null representeerd voor het moedwillig weglaten, of de bedoelde afwezigheid van welk object of waarde dan ook. Het is een van JavaScript's primitive values."><code>null</code></a> en <a href="https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/undefined" title="The documentation about this has not yet been written; please consider contributing!"><code>undefined</code></a> worden vervangen met het globale object en primitieve waardes worden omgezet naar objecten (boxed).</dd> - <dt><code>argsArray</code></dt> - <dd>Een array-achtig object met de argumenten waarmee <em>fun </em>moet worden aangeroepen, of {{jsxref("null")}} of {{jsxref("undefined")}} als er geen argumenten worden gegeven. Vanaf ECMAScript 5 kunnen deze argumenten een generiek array-achtig object zijn in plaats van een array. Hieronder meer informatie over {{anch("Browser_compatibility", "browser compatibiliteit")}}.</dd> -</dl> - -<h3 id="Return_waarde">Return waarde</h3> - -<p>Het resultaat van de aanroep met de gegeven <code>this</code><strong> </strong>waarde en argumenten.</p> - -<h2 id="Omschrijving">Omschrijving</h2> - -<p>Het is mogelijk om een ander <code>this</code> object toe te wijzen indien je een bestaande functie aanroept. <code>this</code> verwijst naar het huidige object, het object dat de aanroep doet. Met <code>apply</code> kun je een methode eenmaal schrijven en het dan door overerving gebruiken in een ander object, zonder dat je de methode hoeft te herschrijven voor het nieuwe object.</p> - -<p><code>Apply</code> heeft veel overeenkomsten met {{jsxref("Function.call", "call()")}} maar heeft voor argumenten een andere notatie. je kunt een array van argumenten meegeven in plaats van een benoemde set aan argumenten. Met apply kun je zowel een array literal (bijv. <code><em>fun</em>.apply(this, ['eat', 'bananas'])</code>) gebruiken als een {{jsxref("Array")}} object (bijv. <code><em>fun</em>.apply(this, new Array('eat', 'bananas'))</code>).</p> - -<p>Je kunt ook {{jsxref("Functions/arguments", "arguments")}} meegeven als <code>argsArray</code> parameter. <code>arguments</code> is een locale variabele of functie, en kan gebruikt worden voor alle ongespecificeerde argumenten voor het aan te roepen object. Dit houdt in dat je niet precies hoeft te weten welke argumenten nodig zijn voor het aan te roepen object als je apply() gebruikt. Het aan te roepen object is vervolgens verantwoordelijk voor de afhandeling van de argumenten.</p> - -<p>Vanaf de 5e editie van ECMAScript kun je ook een willekeurig array-achtig object gebruiken, wat inhoud dat het een <code>length</code> en getallen met bereik <code>(0 ... length-1)</code> als properties heeft. Je kunt bijvoorbeeld een {{domxref("NodeList")}} of een op maat gemaakt object (zoals: <code>{ 'length': 2, '0': 'eat', '1': 'bananas' }</code>) gebruiken.</p> - -<div class="note"> -<p><strong>Let op: </strong>De meeste browsers, waaronder Chrome 14 en Internet Explorer 9, ondersteunen array-achtige objecten nog niet. Deze zullen een exceptie geven als je het toch probeert.</p> -</div> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Apply_gebruiken_om_constructors_te_ketenen">Apply gebruiken om constructors te ketenen</h3> - -<p>Apply kan gebruikt worden om {{jsxref("Operators/new", "constructors", "", 1)}} voor een object aan elkaar te ketenen, gelijk aan de werkwijze in java. In het volgende voorbeeld maken we een globale {{jsxref("Function")}} methode genaamd <code>construct</code>, welke je in staat stelt om een array-achtig object te gebruiken in plaats van een lijst van argumenten.</p> - -<pre class="brush: js notranslate">Function.prototype.construct = function (aArgs) { - var oNew = Object.create(this.prototype); - this.apply(oNew, aArgs); - return oNew; -}; -</pre> - -<div class="note"> -<p><strong>Let op:</strong> De <code>Object.create()</code> methode die hierboven gebruikt wordt is vrij nieuw. Voor een alternatieve methode die gebruik maakt van closures kun je onderstaande voorbeeld ook gebruiken:</p> - -<pre class="brush: js notranslate">Function.prototype.construct = function(aArgs) { - var fConstructor = this, fNewConstr = function() { - fConstructor.apply(this, aArgs); - }; - fNewConstr.prototype = fConstructor.prototype; - return new fNewConstr(); -};</pre> -</div> - -<p>Voorbeeld gebruik:</p> - -<pre class="brush: js notranslate">function MyConstructor() { - for (var nProp = 0; nProp < arguments.length; nProp++) { - this['property' + nProp] = arguments[nProp]; - } -} - -var myArray = [4, 'Hello world!', false]; -var myInstance = MyConstructor.construct(myArray); - -console.log(myInstance.property1); // logs 'Hello world!' -console.log(myInstance instanceof MyConstructor); // logs 'true' -console.log(myInstance.constructor); // logs 'MyConstructor' -</pre> - -<div class="note"> -<p><strong>Let op:</strong> Deze niet native Function.construct methode zal niet werken met sommige native constructors (zoals {{jsxref("Date")}}, bij voorbeeld). In deze gevallen gebruik je de {{jsxref("Function.prototype.bind")}} methode (bij voorbeeld, stel je een array als de volgende voor, te gebruiken met {{jsxref("Global_Objects/Date", "Date")}} constructor: <code>[2012, 11, 4]</code>; in dit geval schrijf je bijvoorbeeld: <code>new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))()</code> — Hoewel dit werkt is dit in meerdere opzichten een kwetsbare manier die niet in productie gebruikt zou moeten worden).</p> -</div> - -<h3 id="Gebruik_van_apply_en_ingebouwde_functies">Gebruik van <code>apply</code> en ingebouwde functies</h3> - -<p>Slim gebruik van apply geeft de mogelijkheid om standaard javascript functies te gebruiken voor handelingen die anders in een loop zouden gebeuren. Als voorbeeld gaan we <code>Math.max</code>/<code>Math.min</code> gebruiken wat de maximum en minimum waardes zijn in een array.</p> - -<pre class="brush: js notranslate">// min/max number in an array -var numbers = [5, 6, 2, 3, 7]; - -// using Math.min/Math.max apply -var max = Math.max.apply(null, numbers); -// This about equal to Math.max(numbers[0], ...) -// or Math.max(5, 6, ...) - -var min = Math.min.apply(null, numbers); - -// vs. simple loop based algorithm -max = -Infinity, min = +Infinity; - -for (var i = 0; i < numbers.length; i++) { - if (numbers[i] > max) { - max = numbers[i]; - } - if (numbers[i] < min) { - min = numbers[i]; - } -} -</pre> - -<p>Maar pas op: door apply op deze manier te gebruiken loop je het risico over de maximum argument limiet van JavaScript's engine heen te gaan. De consequenties van het gebruik van apply op een functie met te veel argumenten (denk aan meer dan tienduizen argumenten) varieren tussen de verschillende engines (JavaScriptCore heeft een hard-coded <a class="link-https" href="https://bugs.webkit.org/show_bug.cgi?id=80797">argument limiet van 65536</a>), omdat de limiet (en het gedrag bij extreem grote hoeveelheden objecten) niet is opgenomen in een standaard. Sommige engines zullen een exceptie opgooien, anderen kunnen mogelijk zelfs het aantal argumenten afkappen bij het maximum. Als je array toch het risico loopt te groeien voorbij de limiet, kun je beter een hybriede implementatie maken: voer je functie uit over stukken van een array, bijvoorbeeld: </p> - -<pre class="brush: js notranslate">function minOfArray(arr) { - var min = Infinity; - var QUANTUM = 32768; - - for (var i = 0, len = arr.length; i < len; i += QUANTUM) { - var submin = Math.min.apply(null, - arr.slice(i, Math.min(i+QUANTUM, len))); - min = Math.min(submin, min); - } - - return min; -} - -var min = minOfArray([5, 6, 2, 3, 7]); -</pre> - -<h3 id="Gebruik_van_apply_bij_monkey-patching">Gebruik van apply bij "monkey-patching"</h3> - -<p>Apply kan enorm nuttig zijn bij het monkey-patchen van browser-eigen- of framework-functies. Met bijvoorbeeld de <code>someobject.foo</code> functie, kun je de functie aanpassen op de volgende, ietwat smerige manier:</p> - -<pre class="brush: js notranslate">var originalfoo = someobject.foo; -someobject.foo = function() { - // Do stuff before calling function - console.log(arguments); - // Call the function as it would have been called normally: - originalfoo.apply(this, arguments); - // Run stuff after, here. -} -</pre> - -<h2 id="Specificaties">Specificaties</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>Initiele definitie. Geimplementeerd in JavaScript 1.3.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.3.4.3', 'Function.prototype.apply')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-function.prototype.apply', 'Function.prototype.apply')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-function.prototype.apply', 'Function.prototype.apply')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td>ES 5.1 generic array-like object as {{jsxref("Functions/arguments", "arguments")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("2.0")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</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> - <tr> - <td>ES 5.1 generic array-like object as {{jsxref("Functions/arguments", "arguments")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoMobile("2.0")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Functions/arguments", "arguments")}} object</li> - <li>{{jsxref("Function.prototype.bind()")}}</li> - <li>{{jsxref("Function.prototype.call()")}}</li> - <li>{{jsxref("Functions", "Functions and function scope", "", 1)}}</li> - <li>{{jsxref("Reflect.apply()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/function/call/index.html b/files/nl/web/javascript/reference/global_objects/function/call/index.html deleted file mode 100644 index aee4b67e7f..0000000000 --- a/files/nl/web/javascript/reference/global_objects/function/call/index.html +++ /dev/null @@ -1,225 +0,0 @@ ---- -title: Function.prototype.call() -slug: Web/JavaScript/Reference/Global_Objects/Function/call -tags: - - Functie - - JavaScript - - Méthode -translation_of: Web/JavaScript/Reference/Global_Objects/Function/call ---- -<div>{{JSRef}}</div> - -<p>De <code><strong>call()</strong></code> methode roept een functie aan met een gegeven <code>this</code> waarde en afzonderlijk gedefineerde argumenten.</p> - -<div class="note"> -<p><strong>Note:</strong> Hoewel de syntax van deze functie vrijwel gelijk is aan die van {{jsxref("Function.prototype.apply", "apply()")}}, zit er een essentieel verschil tussen deze twee. De <code>call()</code> methode accepteert een <span style="font-size: 14px;"><strong>argumentenlijst</strong></span>, terwijl <code>apply()</code> een<strong> enkele array met argumenten </strong>accepteert.</p> -</div> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>function</var>.call(<var>thisArg</var>[, <var>arg1</var>[, <var>arg2</var>[, ...]]])</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>thisArg</code></dt> - <dd>De waarde van <code>this</code> die aan de call voor <code><em>function</em></code> wordt meegegeven. Houd er rekening mee dat dit mogelijk niet de waarde is die de methode ziet: Als de methode gedefineerd is in {{jsxref("Functions_and_function_scope/Strict_mode", "non-strict mode", "", 1)}} code, dan zullen {{jsxref("Global_Objects/null", "null")}} en {{jsxref("Global_Objects/undefined", "undefined")}} worden vervangen met het globale object en primitieve waardes worden omgezet naar objecten.</dd> - <dt><code>arg1, arg2, ...</code></dt> - <dd>De argumenten voor het object.</dd> -</dl> - -<h3 id="Return_waarde">Return waarde</h3> - -<p>Het resultaat van het aanroepen van de functie met de gespecificeerde <strong><code>this</code> </strong>waarde en argumenten.</p> - -<h2 id="Omschrijving">Omschrijving</h2> - -<p>De <code>call()</code> methode staat het toe dat een functie of methode van een object om te worden toegewezen en aangeroepen voor een ander object.</p> - -<p>Een ander <code><strong>this</strong></code> object worden toegewezen als er een bestaande functie wordt aangeroepen. <code>this</code> verwijst in principe naar het huidige object, het object wat de aanroep doet. Met <code>call</code> kun je een methode eenmaal schrijven en dan door overerving gebruiken in een ander object, zonder dat je de methode hoeft te herschrijven voor het nieuwe object.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="call_gebruiken_om_constructors_aan_elkaar_te_ketenen_voor_een_object"><code>call</code> gebruiken om constructors aan elkaar te ketenen voor een object</h3> - -<p><code>call</code> kan gebruikt worden om constructors voor een object aan elkaar te ketenen, vergelijkbaar met de werkwijze in Java. In het volgende voorbeeld is de constructor voor het <code>Product</code> object gedefineerd met twee parameters; <code>name</code> en <code>price</code>. De twee andere functies, <code>Food</code> en <code>Toy</code>, roepen <code>Product</code> aan en geven <code>this</code>, <code>name</code> en <code>price</code> mee. <code>Product</code> initializeert de eigenschappen <code>name</code> en <code>price</code>, en deze gespecializeerde functies defineren de <code>category</code>. </p> - -<pre class="brush: js">function Product(name, price) { - this.name = name; - this.price = price; - - if (price < 0) { - throw RangeError('Cannot create product ' + - this.name + ' with a negative price'); - } -} - -function Food(name, price) { - Product.call(this, name, price); - this.category = 'food'; -} - -function Toy(name, price) { - Product.call(this, name, price); - this.category = 'toy'; -} - -var cheese = new Food('feta', 5); -var fun = new Toy('robot', 40); -</pre> - -<h3 id="call_gebruiken_om_een_anonieme_functie_aan_te_roepen"><code>call</code> gebruiken om een anonieme functie aan te roepen</h3> - -<p>In dit voorbeeld hebben we een anonieme functie, en gebruiken we <code>call</code> om deze aan te roepen voor elk object in een array. Het voornaamste doel van de anonieme functie is het toevoegen van een print functie aan elk object in de array. Het object meegeven als <code>this</code> waarde is niet strict noodzakelijk, maar laat wel de werking zien.</p> - -<pre class="brush: js">var animals = [ - { species: 'Lion', name: 'King' }, - { species: 'Whale', name: 'Fail' } -]; - -for (var i = 0; i < animals.length; i++) { - (function(i) { - this.print = function() { - console.log('#' + i + ' ' + this.species - + ': ' + this.name); - } - this.print(); - }).call(animals[i], i); -} -</pre> - -<h3 id="Call_gebruiken_om_een_functie_aan_te_roepen_en_een_context_te_geven_aan_'this'.">Call gebruiken om een functie aan te roepen en een context te geven aan '<code>this</code>'.</h3> - -<p>In het onderstaande voorbeeld zal de waarde van <code>this</code> gebonden zijn aan het object <code>obj</code> wanneer we <code>greet</code> aanroepen.</p> - -<pre class="brush: js">function greet() { - var reply = [this.person, 'is An Awesome', this.role].join(' '); - console.log(reply); -} - -var obj = { - person: 'Douglas Crockford', role: 'Javascript Developer' -}; - -greet.call(obj); // Douglas Crockford Is An Awesome Javascript Developer -</pre> - -<h3 id="Call_gebruiken_om_een_functie_aan_te_roepen_zonder_eerste_argument">Call gebruiken om een functie aan te roepen zonder eerste argument</h3> - -<p>In het onderstaande voorbeeld roepen we de <code>display</code> functie aan zonder het eerste argument mee te geven. Als het eerste argument niet is meegegeven zal <code>this</code> worden gebonden aan het globale object.</p> - -<pre class="brush: js"><code>var sData = 'Wisen'; - -function display() { - console.log('sData value is %s ', this.sData); -} - -display.call(); // sData value is Wisen</code></pre> - -<div class="blockIndicator note"> -<p><strong>Note:</strong> De waarde van <code>this</code> is <code>undefined</code> in strict mode. Zie onderstaand.</p> -</div> - -<pre class="brush: js"><code>'use strict'; - -var sData = 'Wisen'; - -function display() { - console.log('sData value is %s ', this.sData); -} - -display.call(); // Cannot read the property of 'sData' of undefined</code></pre> - -<h2 id="Specificaties">Specificaties</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>Initiele definitie. Geimplementeerd in JavaScript 1.3.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.3.4.4', 'Function.prototype.call')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-function.prototype.call', 'Function.prototype.call')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-function.prototype.call', 'Function.prototype.call')}}</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>{{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 voor 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("Function.prototype.bind()")}}</li> - <li>{{jsxref("Function.prototype.apply()")}}</li> - <li> - <p><a href="/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript">Introductie voor Object Georienteerd JavaScript</a></p> - </li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/function/index.html b/files/nl/web/javascript/reference/global_objects/function/index.html deleted file mode 100644 index 9cb0571d13..0000000000 --- a/files/nl/web/javascript/reference/global_objects/function/index.html +++ /dev/null @@ -1,236 +0,0 @@ ---- -title: Function -slug: Web/JavaScript/Reference/Global_Objects/Function -tags: - - Constructor - - Function - - JavaScript - - NeedsTranslation - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/Function ---- -<div>{{JSRef}}</div> - -<p>The <strong><code>Function</code> constructor</strong> creates a new <code>Function</code> object. In JavaScript every function is actually a <code>Function</code> object.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>new Function ([<var>arg1</var>[, <var>arg2</var>[, ...<var>argN</var>]],] <var>functionBody</var>)</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>arg1, arg2, ... arg<em>N</em></code></dt> - <dd>Names to be used by the function as formal argument names. Each must be a string that corresponds to a valid JavaScript identifier or a list of such strings separated with a comma; for example "<code>x</code>", "<code>theValue</code>", or "<code>a,b</code>".</dd> - <dt><code>functionBody</code></dt> - <dd>A string containing the JavaScript statements comprising the function definition.</dd> -</dl> - -<h2 id="Description">Description</h2> - -<p><code>Function</code> objects created with the <code>Function</code> constructor are parsed when the function is created. This is less efficient than declaring a function with a <a href="/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a> or <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function statement</a> and calling it within your code, because such functions are parsed with the rest of the code.</p> - -<p>All arguments passed to the function are treated as the names of the identifiers of the parameters in the function to be created, in the order in which they are passed.</p> - -<div class="note"> -<p><strong>Note:</strong> Functions created with the <code>Function</code> constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access their own local variables and global ones, not the ones from the scope in which the <code>Function</code> constructor was called. This is different from using {{jsxref("eval")}} with code for a function expression.</p> -</div> - -<p>Invoking the <code>Function</code> constructor as a function (without using the <code>new</code> operator) has the same effect as invoking it as a constructor.</p> - -<h2 id="Properties_and_Methods_of_Function">Properties and Methods of <code>Function</code></h2> - -<p>The global <code>Function</code> object has no methods or properties of its own, however, since it is a function itself it does inherit some methods and properties through the prototype chain from {{jsxref("Function.prototype")}}.</p> - -<h2 id="Function_prototype_object"><code>Function</code> prototype object</h2> - -<h3 id="Properties">Properties</h3> - -<div>{{page('/en-US/docs/JavaScript/Reference/Global_Objects/Function/prototype', 'Properties')}}</div> - -<h3 id="Methods">Methods</h3> - -<div>{{page('/en-US/docs/JavaScript/Reference/Global_Objects/Function/prototype', 'Methods')}}</div> - -<h2 id="Function_instances"><code>Function</code> instances</h2> - -<p><code>Function</code> instances inherit methods and properties from {{jsxref("Function.prototype")}}. As with all constructors, you can change the constructor's prototype object to make changes to all <code>Function</code> instances.</p> - -<h2 id="Examples">Examples</h2> - -<h3 id="Specifying_arguments_with_the_Function_constructor">Specifying arguments with the <code>Function</code> constructor</h3> - -<p>The following code creates a <code>Function</code> object that takes two arguments.</p> - -<pre class="brush: js">// Example can be run directly in your JavaScript console - -// Create a function that takes two arguments and returns the sum of those arguments -var adder = new Function('a', 'b', 'return a + b'); - -// Call the function -adder(2, 6); -// > 8 -</pre> - -<p>The arguments "<code>a</code>" and "<code>b</code>" are formal argument names that are used in the function body, "<code>return a + b</code>".</p> - -<h3 id="A_recursive_shortcut_to_massively_modify_the_DOM">A recursive shortcut to massively modify the DOM</h3> - -<p>Creating functions with the <code>Function</code> constructor is one of the ways to dynamically create an indeterminate number of new objects with some executable code into the global scope from a function. The following example (a recursive shortcut to massively modify the DOM) is impossible without the invocation of the <code>Function</code> constructor for each new query if you want to avoid closures.</p> - -<pre class="brush: html"><!doctype html> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<title>MDN Example - a recursive shortcut to massively modify the DOM</title> -<script type="text/javascript"> -var domQuery = (function() { - var aDOMFunc = [ - Element.prototype.removeAttribute, - Element.prototype.setAttribute, - CSSStyleDeclaration.prototype.removeProperty, - CSSStyleDeclaration.prototype.setProperty - ]; - - function setSomething(bStyle, sProp, sVal) { - var bSet = Boolean(sVal), fAction = aDOMFunc[bSet | bStyle << 1], - aArgs = Array.prototype.slice.call(arguments, 1, bSet ? 3 : 2), - aNodeList = bStyle ? this.cssNodes : this.nodes; - - if (bSet && bStyle) { aArgs.push(''); } - for ( - var nItem = 0, nLen = this.nodes.length; - nItem < nLen; - fAction.apply(aNodeList[nItem++], aArgs) - ); - this.follow = setSomething.caller; - return this; - } - - function setStyles(sProp, sVal) { return setSomething.call(this, true, sProp, sVal); } - function setAttribs(sProp, sVal) { return setSomething.call(this, false, sProp, sVal); } - function getSelectors() { return this.selectors; }; - function getNodes() { return this.nodes; }; - - return (function(sSelectors) { - var oQuery = new Function('return arguments.callee.follow.apply(arguments.callee, arguments);'); - oQuery.selectors = sSelectors; - oQuery.nodes = document.querySelectorAll(sSelectors); - oQuery.cssNodes = Array.prototype.map.call(oQuery.nodes, function(oInlineCSS) { return oInlineCSS.style; }); - oQuery.attributes = setAttribs; - oQuery.inlineStyle = setStyles; - oQuery.follow = getNodes; - oQuery.toString = getSelectors; - oQuery.valueOf = getNodes; - return oQuery; - }); -})(); -</script> -</head> - -<body> - -<div class="testClass">Lorem ipsum</div> -<p>Some text</p> -<div class="testClass">dolor sit amet</div> - -<script type="text/javascript"> -domQuery('.testClass') - .attributes('lang', 'en')('title', 'Risus abundat in ore stultorum') - .inlineStyle('background-color', 'black')('color', 'white')('width', '100px')('height', '50px'); -</script> -</body> - -</html> -</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. Implemented in JavaScript 1.0.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.3', 'Function')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-function-objects', 'Function')}}</td> - <td>{{Spec2('ES6')}}</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>{{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("Functions", "Functions and function scope")}}</li> - <li>{{jsxref("Function")}}</li> - <li>{{jsxref("Statements/function", "function statement")}}</li> - <li>{{jsxref("Operators/function", "function expression")}}</li> - <li>{{jsxref("Statements/function*", "function* statement")}}</li> - <li>{{jsxref("Operators/function*", "function* expression")}}</li> - <li>{{jsxref("GeneratorFunction")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/index.html b/files/nl/web/javascript/reference/global_objects/index.html deleted file mode 100644 index 7395446f35..0000000000 --- a/files/nl/web/javascript/reference/global_objects/index.html +++ /dev/null @@ -1,183 +0,0 @@ ---- -title: Standard built-in objects -slug: Web/JavaScript/Reference/Global_Objects -tags: - - JavaScript - - NeedsTranslation - - Objects - - Reference - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects ---- -<div>{{jsSidebar("Objects")}}</div> - -<p>This chapter documents all of JavaScript's standard, built-in objects, including their methods and properties.</p> - -<div class="onlyinclude"> -<p>The term "global objects" (or standard built-in objects) here is not to be confused with the <strong>global object</strong>. Here, global objects refer to <strong>objects in the global scope</strong> (but only if ECMAScript 5 strict mode is not used; in that case it returns {{jsxref("undefined")}}). The <strong>global object</strong> itself can be accessed using the {{jsxref("Operators/this", "this")}} operator in the global scope. In fact, the global scope <strong>consists of</strong> the properties of the global object, including inherited properties, if any.</p> - -<p>Other objects in the global scope are either <a href="/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Creating_new_objects">created by the user script</a> or provided by the host application. The host objects available in browser contexts are documented in the <a href="/en-US/docs/Web/API/Reference">API reference</a>. For more information about the distinction between the <a href="/en-US/docs/DOM/DOM_Reference">DOM</a> and core <a href="/en-US/docs/Web/JavaScript">JavaScript</a>, see <a href="/en-US/docs/Web/JavaScript/JavaScript_technologies_overview">JavaScript technologies overview</a>.</p> - -<h2 id="Standard_objects_(by_category)">Standard objects (by category)</h2> - -<h3 id="Value_properties">Value properties</h3> - -<p>These global properties return a simple value; they have no properties or methods.</p> - -<ul> - <li>{{jsxref("Infinity")}}</li> - <li>{{jsxref("NaN")}}</li> - <li>{{jsxref("undefined")}}</li> - <li>{{jsxref("null")}} literal</li> -</ul> - -<h3 id="Function_properties">Function properties</h3> - -<p>These global functions—functions which are called globally rather than on an object—directly return their results to the caller.</p> - -<ul> - <li>{{jsxref("Global_Objects/eval", "eval()")}}</li> - <li>{{jsxref("Global_Objects/uneval", "uneval()")}} {{non-standard_inline}}</li> - <li>{{jsxref("Global_Objects/isFinite", "isFinite()")}}</li> - <li>{{jsxref("Global_Objects/isNaN", "isNaN()")}}</li> - <li>{{jsxref("Global_Objects/parseFloat", "parseFloat()")}}</li> - <li>{{jsxref("Global_Objects/parseInt", "parseInt()")}}</li> - <li>{{jsxref("Global_Objects/decodeURI", "decodeURI()")}}</li> - <li>{{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent()")}}</li> - <li>{{jsxref("Global_Objects/encodeURI", "encodeURI()")}}</li> - <li>{{jsxref("Global_Objects/encodeURIComponent", "encodeURIComponent()")}}</li> - <li>{{jsxref("Global_Objects/escape", "escape()")}} {{deprecated_inline}}</li> - <li>{{jsxref("Global_Objects/unescape", "unescape()")}} {{deprecated_inline}}</li> -</ul> - -<h3 id="Fundamental_objects">Fundamental objects</h3> - -<p>These are the fundamental, basic objects upon which all other objects are based. This includes objects that represent general objects, functions, and errors.</p> - -<ul> - <li>{{jsxref("Object")}}</li> - <li>{{jsxref("Function")}}</li> - <li>{{jsxref("Boolean")}}</li> - <li>{{jsxref("Symbol")}} {{experimental_inline}}</li> - <li>{{jsxref("Error")}}</li> - <li>{{jsxref("EvalError")}}</li> - <li>{{jsxref("InternalError")}}</li> - <li>{{jsxref("RangeError")}}</li> - <li>{{jsxref("ReferenceError")}}</li> - <li>{{jsxref("SyntaxError")}}</li> - <li>{{jsxref("TypeError")}}</li> - <li>{{jsxref("URIError")}}</li> -</ul> - -<h3 id="Numbers_and_dates">Numbers and dates</h3> - -<p>These are the base objects representing numbers, dates, and mathematical calculations.</p> - -<ul> - <li>{{jsxref("Number")}}</li> - <li>{{jsxref("Math")}}</li> - <li>{{jsxref("Date")}}</li> -</ul> - -<h3 id="Text_processing">Text processing</h3> - -<p>These objects represent strings and support manipulating them.</p> - -<ul> - <li>{{jsxref("String")}}</li> - <li>{{jsxref("RegExp")}}</li> -</ul> - -<h3 id="Indexed_collections">Indexed collections</h3> - -<p>These objects represent collections of data which are ordered by an index value. This includes (typed) arrays and array-like constructs.</p> - -<ul> - <li>{{jsxref("Array")}}</li> - <li>{{jsxref("Int8Array")}}</li> - <li>{{jsxref("Uint8Array")}}</li> - <li>{{jsxref("Uint8ClampedArray")}}</li> - <li>{{jsxref("Int16Array")}}</li> - <li>{{jsxref("Uint16Array")}}</li> - <li>{{jsxref("Int32Array")}}</li> - <li>{{jsxref("Uint32Array")}}</li> - <li>{{jsxref("Float32Array")}}</li> - <li>{{jsxref("Float64Array")}}</li> -</ul> - -<h3 id="Keyed_collections">Keyed collections</h3> - -<p>These objects represent collections which use keys; these contain elements which are iterable in the order of insertion.</p> - -<ul> - <li>{{jsxref("Map")}} {{experimental_inline}}</li> - <li>{{jsxref("Set")}} {{experimental_inline}}</li> - <li>{{jsxref("WeakMap")}} {{experimental_inline}}</li> - <li>{{jsxref("WeakSet")}} {{experimental_inline}}</li> -</ul> - -<h3 id="Vector_collections">Vector collections</h3> - -<p>{{Glossary("SIMD")}} vector data types are objects where data is arranged into lanes.</p> - -<ul> - <li>{{jsxref("SIMD")}} {{experimental_inline}}</li> - <li>{{jsxref("float32x4", "SIMD.float32x4")}} {{experimental_inline}}</li> - <li>{{jsxref("float64x2", "SIMD.float64x2")}} {{experimental_inline}}</li> - <li>{{jsxref("int8x16", "SIMD.int8x16")}} {{experimental_inline}}</li> - <li>{{jsxref("int16x8", "SIMD.int16x8")}} {{experimental_inline}}</li> - <li>{{jsxref("int32x4", "SIMD.int32x4")}} {{experimental_inline}}</li> -</ul> - -<h3 id="Structured_data">Structured data</h3> - -<p>These objects represent and interact with structured data buffers and data coded using JavaScript Object Notation (JSON).</p> - -<ul> - <li>{{jsxref("ArrayBuffer")}}</li> - <li>{{jsxref("DataView")}}</li> - <li>{{jsxref("JSON")}}</li> -</ul> - -<h3 id="Control_abstraction_objects">Control abstraction objects</h3> - -<ul> - <li>{{jsxref("Promise")}} {{experimental_inline}}</li> - <li>{{jsxref("Generator")}} {{experimental_inline}}</li> - <li>{{jsxref("GeneratorFunction")}} {{experimental_inline}}</li> -</ul> - -<h3 id="Reflection">Reflection</h3> - -<ul> - <li>{{jsxref("Reflect")}} {{experimental_inline}}</li> - <li>{{jsxref("Proxy")}} {{experimental_inline}}</li> -</ul> - -<h3 id="Internationalization">Internationalization</h3> - -<p>Additions to the ECMAScript core for language-sensitive functionalities.</p> - -<ul> - <li>{{jsxref("Intl")}}</li> - <li>{{jsxref("Global_Objects/Collator", "Intl.Collator")}}</li> - <li>{{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}</li> - <li>{{jsxref("Global_Objects/NumberFormat", "Intl.NumberFormat")}}</li> -</ul> - -<h3 id="Non-standard_objects">Non-standard objects</h3> - -<ul> - <li>{{jsxref("Iterator")}} {{non-standard_inline}}</li> - <li>{{jsxref("ParallelArray")}} {{non-standard_inline}}</li> - <li>{{jsxref("StopIteration")}} {{non-standard_inline}}</li> -</ul> - -<h3 id="Other">Other</h3> - -<ul> - <li><code><a href="/en-US/docs/Web/JavaScript/Reference/Functions/arguments">arguments</a></code></li> -</ul> -</div> - -<p> </p> diff --git a/files/nl/web/javascript/reference/global_objects/isfinite/index.html b/files/nl/web/javascript/reference/global_objects/isfinite/index.html deleted file mode 100644 index eaee2238aa..0000000000 --- a/files/nl/web/javascript/reference/global_objects/isfinite/index.html +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: isFinite() -slug: Web/JavaScript/Reference/Global_Objects/isFinite -tags: - - JavaScript -translation_of: Web/JavaScript/Reference/Global_Objects/isFinite ---- -<div>{{jsSidebar("Objects")}}</div> - -<p>De globale functie <code><strong>isFinite()</strong></code> bepaalt of de doorgegeven waarde een eindig getal is. Wanneer nodig wordt de parameter eerst omgezet naar een getal.</p> - -<h2 id="Syntaxis">Syntaxis</h2> - -<pre class="syntaxbox">isFinite(<em>testValue</em>)</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>testValue</code></dt> - <dd>De waarde die op eindigheid wordt getest.</dd> -</dl> - -<h3 id="Retourwaarde">Retourwaarde</h3> - -<p><strong><code>false</code></strong> als de waarde positief is of negatief {{jsxref("Infinity")}} of {{jsxref("NaN")}}; anders, <strong><code>true</code></strong>.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p><code>isFinite</code> is een top-levelfunctie en is niet geassocieerd met een object.</p> - -<p>Deze functie is te gebruiken om te bepalen of een getal eindig is. De functie <code>isFinite</code> controleert het getal in het argument. Als het argument <code>NaN</code> is, positief oneindig, of negatief oneindig, geeft deze methode <code>false</code> terug; anders geeft deze <code>true</code> terug.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<pre class="brush: js">isFinite(Infinity); // false -isFinite(NaN); // false -isFinite(-Infinity); // false - -isFinite(0); // true -isFinite(2e64); // true -isFinite(910); // true - -isFinite(null); // true, met het robuustere Number.isFinite(null) zou - // deze waarde <code>false</code> zijn geweest. - -isFinite('0'); // true, met het robuustere Number.isFinite("0") zou - // deze waarde <code>false</code> zijn geweest. -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Initiële definitie.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.1.2.5', 'isFinite')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-isfinite-number', 'isFinite')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-isfinite-number', 'isFinite')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browsercompatibiliteit">Browsercompatibiliteit</h2> - -<div class="hidden">De compatibiliteitstabel op deze pagina wordt uit gestructureerde gegevens gegenereerd. Als u aan de gegevens wilt bijdragen, bekijk dan <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> en stuur ons een pull request.</div> - -<p>{{Compat("javascript.builtins.isFinite")}}</p> - -<h2 id="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Number.isFinite()")}}</li> - <li>{{jsxref("Number.NaN")}}</li> - <li>{{jsxref("Number.POSITIVE_INFINITY")}}</li> - <li>{{jsxref("Number.NEGATIVE_INFINITY")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/null/index.html b/files/nl/web/javascript/reference/global_objects/null/index.html deleted file mode 100644 index 4a5abdaa2d..0000000000 --- a/files/nl/web/javascript/reference/global_objects/null/index.html +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: 'null' -slug: Web/JavaScript/Reference/Global_Objects/null -translation_of: Web/JavaScript/Reference/Global_Objects/null ---- -<div>{{jsSidebar("Objects")}}</div> - -<p>De waarde <code>null</code> representeert het moedwillig weglaten, of de bedoelde afwezigheid van welk object of waarde dan ook. Het is een van JavaScript's {{Glossary("Primitive", "primitive values")}}.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>null </code></pre> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De waarde <code>null</code> wordt letterlijk geschreven als <code>null</code> (het is geen idenfifier voor een eigenschap van de global object zoals {{jsxref("Global_Objects/undefined","undefined")}} wel kan zijn). In APIs, wordt <code>null</code> vaak verkregen op plekken waar een object mag worden verwacht, maar waar tegelijk geen object relevant is . Wanneer op null of undefined wordt gecontroleerd, wees dan bewust van de <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">verschillen tussen equality (==) en identity (===) operators</a> (type-conversie wordt via de eerste bereikt).</p> - -<pre class="brush: js">// foo does not exist. It is not defined and has never been initialized: -> foo -"ReferenceError: foo is not defined" - -// foo is known to exist now but it has no type or value: -> var foo = null; foo -"null" -</pre> - -<h3 id="Verschil_tussen_null_en_undefined">Verschil tussen <code>null</code> en <code> undefined</code></h3> - -<pre class="brush: js">typeof null // object (bug in ECMAScript, should be null) -typeof undefined // undefined -null === undefined // false -null == undefined // true -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Commentaar</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-4.3.11', 'null value')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-null-value', 'null value')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-null-value', 'null value')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("undefined")}}</li> - <li>{{jsxref("NaN")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/object/index.html b/files/nl/web/javascript/reference/global_objects/object/index.html deleted file mode 100644 index 52aaef2901..0000000000 --- a/files/nl/web/javascript/reference/global_objects/object/index.html +++ /dev/null @@ -1,226 +0,0 @@ ---- -title: Object -slug: Web/JavaScript/Reference/Global_Objects/Object -tags: - - Constructor - - JavaScript - - NeedsTranslation - - Object - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/Object ---- -<div>{{JSRef}}</div> - -<p>The <code><strong>Object</strong></code> constructor creates an object wrapper.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code>// Object initialiser or literal -{ [ <var>nameValuePair1</var>[, <var>nameValuePair2</var>[, ...<var>nameValuePairN</var>] ] ] } - -// Called as a constructor -new Object([<var>value</var>])</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>nameValuePair1, nameValuePair2, ... nameValuePair<em>N</em></code></dt> - <dd>Pairs of names (strings) and values (any value) where the name is separated from the value by a colon.</dd> - <dt><code>value</code></dt> - <dd>Any value.</dd> -</dl> - -<h2 id="Description">Description</h2> - -<p>The <code>Object</code> constructor creates an object wrapper for the given value. If the value is {{jsxref("null")}} or {{jsxref("undefined")}}, it will create and return an empty object, otherwise, it will return an object of a Type that corresponds to the given value. If the value is an object already, it will return the value.</p> - -<p>When called in a non-constructor context, <code>Object</code> behaves identically to <code>new Object()</code>.</p> - -<p>See also the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">object initializer / literal syntax</a>.</p> - -<h2 id="Properties_of_the_Object_constructor">Properties of the <code>Object</code> constructor</h2> - -<dl> - <dt><code>Object.length</code></dt> - <dd>Has a value of 1.</dd> - <dt>{{jsxref("Object.prototype")}}</dt> - <dd>Allows the addition of properties to all objects of type Object.</dd> -</dl> - -<h2 id="Methods_of_the_Object_constructor">Methods of the <code>Object</code> constructor</h2> - -<dl> - <dt>{{jsxref("Object.assign()")}}</dt> - <dd>Creates a new object by copying the values of all enumerable own properties from one or more source objects to a target object.</dd> - <dt>{{jsxref("Object.create()")}}</dt> - <dd>Creates a new object with the specified prototype object and properties.</dd> - <dt>{{jsxref("Object.defineProperty()")}}</dt> - <dd>Adds the named property described by a given descriptor to an object.</dd> - <dt>{{jsxref("Object.defineProperties()")}}</dt> - <dd>Adds the named properties described by the given descriptors to an object.</dd> - <dt>{{jsxref("Object.entries()")}} {{experimental_inline}}</dt> - <dd>Returns an array of a given object's own enumerable property <code>[key, value]</code> pairs.</dd> - <dt>{{jsxref("Object.freeze()")}}</dt> - <dd>Freezes an object: other code can't delete or change any properties.</dd> - <dt>{{jsxref("Object.getOwnPropertyDescriptor()")}}</dt> - <dd>Returns a property descriptor for a named property on an object.</dd> - <dt>{{jsxref("Object.getOwnPropertyNames()")}}</dt> - <dd>Returns an array containing the names of all of the given object's <strong>own</strong> enumerable and non-enumerable properties.</dd> - <dt>{{jsxref("Object.getOwnPropertySymbols()")}}</dt> - <dd>Returns an array of all symbol properties found directly upon a given object.</dd> - <dt>{{jsxref("Object.getPrototypeOf()")}}</dt> - <dd>Returns the prototype of the specified object.</dd> - <dt>{{jsxref("Object.is()")}}</dt> - <dd>Compares if two values are distinguishable (ie. the same)</dd> - <dt>{{jsxref("Object.isExtensible()")}}</dt> - <dd>Determines if extending of an object is allowed.</dd> - <dt>{{jsxref("Object.isFrozen()")}}</dt> - <dd>Determines if an object was frozen.</dd> - <dt>{{jsxref("Object.isSealed()")}}</dt> - <dd>Determines if an object is sealed.</dd> - <dt>{{jsxref("Object.keys()")}}</dt> - <dd>Returns an array containing the names of all of the given object's <strong>own</strong> enumerable properties.</dd> - <dt>{{jsxref("Object.observe()")}} {{non-standard_inline}}</dt> - <dd>Asynchronously observes changes to an object.</dd> - <dt>{{jsxref("Object.getNotifier()")}} {{non-standard_inline}}</dt> - <dd>Get a notifier with which to create object changes manually.</dd> - <dt>{{jsxref("Object.preventExtensions()")}}</dt> - <dd>Prevents any extensions of an object.</dd> - <dt>{{jsxref("Object.seal()")}}</dt> - <dd>Prevents other code from deleting properties of an object.</dd> - <dt>{{jsxref("Object.setPrototypeOf()")}}</dt> - <dd>Sets the prototype (i.e., the internal <code>[[Prototype]]</code> property)</dd> - <dt>{{jsxref("Object.unobserve()")}} {{non-standard_inline}}</dt> - <dd>Unobserves changes to an object.</dd> - <dt>{{jsxref("Object.values()")}} {{experimental_inline}}</dt> - <dd>Returns an array of a given object's own enumerable values.</dd> -</dl> - -<h2 id="Object_instances_and_Object_prototype_object"><code>Object</code> instances and <code>Object</code> prototype object</h2> - -<p>All objects in JavaScript are descended from <code>Object</code>; all objects inherit methods and properties from {{jsxref("Object.prototype")}}, although they may be overridden. For example, other constructors' prototypes override the <code>constructor</code> property and provide their own <code>toString()</code> methods. Changes to the <code>Object</code> prototype object are propagated to all objects unless the properties and methods subject to those changes are overridden further along the prototype chain.</p> - -<h3 id="Properties">Properties</h3> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Properties') }}</div> - -<h3 id="Methods">Methods</h3> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/prototype', 'Methods') }}</div> - -<h2 id="Examples">Examples</h2> - -<h3 id="Using_Object_given_undefined_and_null_types">Using <code>Object</code> given <code>undefined</code> and <code>null</code> types</h3> - -<p>The following examples store an empty <code>Object</code> object in <code>o</code>:</p> - -<pre class="brush: js">var o = new Object(); -</pre> - -<pre class="brush: js">var o = new Object(undefined); -</pre> - -<pre class="brush: js">var o = new Object(null); -</pre> - -<h3 id="Using_Object_to_create_Boolean_objects">Using <code>Object</code> to create <code>Boolean</code> objects</h3> - -<p>The following examples store {{jsxref("Boolean")}} objects in <code>o</code>:</p> - -<pre class="brush: js">// equivalent to o = new Boolean(true); -var o = new Object(true); -</pre> - -<pre class="brush: js">// equivalent to o = new Boolean(false); -var o = new Object(Boolean()); -</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. Implemented in JavaScript 1.0.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.2', 'Object')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-object-objects', 'Object')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Added Object.assign, Object.getOwnPropertySymbols, Object.setPrototypeOf</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-object-objects', 'Object')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td>Added Object.entries and Object.values.</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>{{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><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer">Object initializer</a></li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/parsefloat/index.html b/files/nl/web/javascript/reference/global_objects/parsefloat/index.html deleted file mode 100644 index e88af6c4b3..0000000000 --- a/files/nl/web/javascript/reference/global_objects/parsefloat/index.html +++ /dev/null @@ -1,168 +0,0 @@ ---- -title: parseFloat() -slug: Web/JavaScript/Reference/Global_Objects/parseFloat -tags: - - JavaScript -translation_of: Web/JavaScript/Reference/Global_Objects/parseFloat ---- -<div> -<div> -<div>{{jsSidebar("Objects")}}</div> -</div> -</div> - -<p>De <code><strong>parseFloat()</strong></code> functie verwerkt een string argument en geeft een floating point nummer terug.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox">parseFloat(<em>string</em>)</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>string</code></dt> - <dd>Een string waarde die je wilt verwerken.</dd> -</dl> - -<h2 id="Omschrijving">Omschrijving</h2> - -<p><code>parseFloat</code> is een top-level functie en is niet verbonden met welk object dan ook.</p> - -<p><code>parseFloat</code> verwerkt het argument , een string, en geeft een floating point nummer terug. Als het een ander karakter tegenkomt dan een teken (+ or -), nummerieke waarde (0-9), een decimale punt , of een exponent, dan geeft het de waarde tot dat karakter terug en negeert dat karakter en alle daaropvolgende karakters. Spaties aan het begin en einde van de string zijn toegestaan.</p> - -<p>Als het eerste karakter niet in een nummer kan worden veranderd zal <code>parseFloat</code> het resultaat NaN opleveren.</p> - -<p>Voor wiskundige doeleinden, de waarde <code>NaN</code> is geen nummer met een radix. Je kunt de functie {{jsxref("isNaN")}} gebruiken om vast te stellen of het resultaat van <code>parseFloat</code> <code>NaN is</code>. Als NaN in een wiskundige operatie wordt gebruikt is het resultaat ook NaN.</p> - -<p><code>parseFloat</code> kan ook de waarde Infinity verwerken en het resultaat is Infinity. Je kunt de functie {{jsxref("isFinite")}} gebruiken om vast te stellen of het resultaat een eindig getal is (niet <code>Infinity</code>, <code>-Infinity</code>, of <code>NaN</code>).</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="parseFloat_levert_een_nummer_op"><code>parseFloat</code> levert een nummer op</h3> - -<p>Het resultaat van de volgende voorbeelden is <strong>3.14</strong></p> - -<pre class="brush:js">parseFloat("3.14"); -parseFloat("314e-2"); -parseFloat("0.0314E+2"); -parseFloat("3.14more non-digit characters"); -</pre> - -<h3 id="parseFloat_levert_NaN_op"><code>parseFloat</code> levert NaN op</h3> - -<p>Het volgende voorbeeld heeft als resultaat NaN</p> - -<pre class="brush: js">parseFloat("FF2"); -</pre> - -<h3 id="Een_bondigere_parse_function">Een bondigere parse function</h3> - -<p>Soms is het handig om een bondigere manier te hebben om float waardes om te zetten, regular expressions helpen hierbij :</p> - -<pre class="brush: js">var filterFloat = function (value) { - if(/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/ - .test(value)) - return Number(value); - return NaN; -} - -console.log(filterFloat('421')); // 421 -console.log(filterFloat('-421')); // -421 -console.log(filterFloat('+421')); // 421 -console.log(filterFloat('Infinity')); // Infinity -console.log(filterFloat('1.61803398875')); // 1.61803398875 -console.log(filterFloat('421e+0')); // NaN -console.log(filterFloat('421hop')); // NaN -console.log(filterFloat('hop1.61803398875')); // NaN - -</pre> - -<p>Deze code is alleen een voorbeeld. Het accepteert geen geldige nummers zoals 1 <strong>. </strong>of <strong>. </strong>5.</p> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Commentaar</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Eerste definitie.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.1.2.3', 'parseFloat')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-parsefloat-string', 'parseFloat')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compabiliteit">Browser compabiliteit</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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("Global_Objects/parseInt", "parseInt()")}}</li> - <li>{{jsxref("Number.parseFloat()")}}</li> - <li>{{jsxref("Number.parseInt()")}}</li> - <li>{{jsxref("Global_Objects/isNaN", "isNaN()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/string/index.html b/files/nl/web/javascript/reference/global_objects/string/index.html deleted file mode 100644 index a4847a7626..0000000000 --- a/files/nl/web/javascript/reference/global_objects/string/index.html +++ /dev/null @@ -1,409 +0,0 @@ ---- -title: String -slug: Web/JavaScript/Reference/Global_Objects/String -tags: - - ECMAScript6 - - JavaScript - - NeedsTranslation - - Reference - - String - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/String ---- -<div>{{JSRef}}</div> - -<p>The <strong><code>String</code></strong> global object is a constructor for strings, or a sequence of characters.</p> - -<h2 id="Syntax">Syntax</h2> - -<p>String literals take the forms:</p> - -<pre class="syntaxbox"><code>'string text' -"string text" -"中文 español English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ்"</code></pre> - -<p>Strings can also be created using the <code>String</code> global object directly:</p> - -<pre class="syntaxbox"><code>String(thing) -</code></pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>thing</code></dt> - <dd>Anything to be converted to a string.</dd> -</dl> - -<h3 id="Template_strings">Template strings</h3> - -<p>Since ECMAScript 2015, string literals can also be so-called <a href="/en-US/docs/Web/JavaScript/Reference/template_strings">Template strings</a>:</p> - -<pre class="brush: js"><code>`hello world`</code> -`hello! - world!` -<code>`hello ${who}`</code> -<code>escape `<a>${who}</a>`</code></pre> - -<dl> -</dl> - -<h3 id="Escape_notation">Escape notation</h3> - -<p>Beside regular, printable characters, special characters can be encoded using escape notation:</p> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Code</th> - <th scope="col">Output</th> - </tr> - </thead> - <tbody> - <tr> - <td><code>\0</code></td> - <td>the NULL character</td> - </tr> - <tr> - <td><code>\'</code></td> - <td>single quote</td> - </tr> - <tr> - <td><code>\"</code></td> - <td>double quote</td> - </tr> - <tr> - <td><code>\\</code></td> - <td>backslash</td> - </tr> - <tr> - <td><code>\n</code></td> - <td>new line</td> - </tr> - <tr> - <td><code>\r</code></td> - <td>carriage return</td> - </tr> - <tr> - <td><code>\v</code></td> - <td>vertical tab</td> - </tr> - <tr> - <td><code>\t</code></td> - <td>tab</td> - </tr> - <tr> - <td><code>\b</code></td> - <td>backspace</td> - </tr> - <tr> - <td><code>\f</code></td> - <td>form feed</td> - </tr> - <tr> - <td><code>\uXXXX</code></td> - <td>unicode codepoint</td> - </tr> - <tr> - <td><code>\u{X}</code> ... <code>\u{XXXXXX}</code></td> - <td>unicode codepoint {{experimental_inline}}</td> - </tr> - <tr> - <td><code>\xXX</code></td> - <td>the Latin-1 character</td> - </tr> - </tbody> -</table> - -<p>NOTE: Unlike some other languages, JavaScript makes no distinction between single-quoted strings and double-quoted strings, therefore, the escape sequences above work in strings created with either single or double quotes.</p> - -<dl> -</dl> - -<h3 id="Long_literal_strings">Long literal strings</h3> - -<p>Sometimes, your code will include strings which are very long. Rather than having lines that go on endlessly, or wrap at the whim of your editor, you may wish to specifically break the string into multiple lines in the source code without affecting the actual string contents. There are two ways you can do this.</p> - -<p>You can use the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition_()">+</a> operator to append multiple strings together, like this:</p> - -<pre class="brush: js">let longString = "This is a very long string which needs " + - "to wrap across multiple lines because " + - "otherwise my code is unreadable."; -</pre> - -<p>Or you can use the backslash character ("\") at the end of each line to indicate that the string will continue on the next line. Make sure there is no space or any other character after the backslash (except for a line break), or as an indent; otherwise it will not work. That form looks like this:</p> - -<pre class="brush: js">let longString = "This is a very long string which needs \ -to wrap across multiple lines because \ -otherwise my code is unreadable."; -</pre> - -<p>Both of these result in identical strings being created.</p> - -<h2 id="Description">Description</h2> - -<p>Strings are useful for holding data that can be represented in text form. Some of the most-used operations on strings are to check their {{jsxref("String.length", "length")}}, to build and concatenate them using the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/String_Operators">+ and += string operators</a>, checking for the existence or location of substrings with the {{jsxref("String.prototype.indexOf()", "indexOf()")}} method, or extracting substrings with the {{jsxref("String.prototype.substring()", "substring()")}} method.</p> - -<h3 id="Character_access">Character access</h3> - -<p>There are two ways to access an individual character in a string. The first is the {{jsxref("String.prototype.charAt()", "charAt()")}} method:</p> - -<pre class="brush: js">return 'cat'.charAt(1); // returns "a" -</pre> - -<p>The other way (introduced in ECMAScript 5) is to treat the string as an array-like object, where individual characters correspond to a numerical index:</p> - -<pre class="brush: js">return 'cat'[1]; // returns "a" -</pre> - -<p>For character access using bracket notation, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See {{jsxref("Object.defineProperty()")}} for more information.)</p> - -<h3 id="Comparing_strings">Comparing strings</h3> - -<p>C developers have the <code>strcmp()</code> function for comparing strings. In JavaScript, you just use the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">less-than and greater-than operators</a>:</p> - -<pre class="brush: js">var a = 'a'; -var b = 'b'; -if (a < b) { // true - console.log(a + ' is less than ' + b); -} else if (a > b) { - console.log(a + ' is greater than ' + b); -} else { - console.log(a + ' and ' + b + ' are equal.'); -} -</pre> - -<p>A similar result can be achieved using the {{jsxref("String.prototype.localeCompare()", "localeCompare()")}} method inherited by <code>String</code> instances.</p> - -<h3 id="Distinction_between_string_primitives_and_String_objects">Distinction between string primitives and <code>String</code> objects</h3> - -<p>Note that JavaScript distinguishes between <code>String</code> objects and primitive string values. (The same is true of {{jsxref("Boolean")}} and {{jsxref("Global_Objects/Number", "Numbers")}}.)</p> - -<p>String literals (denoted by double or single quotes) and strings returned from <code>String</code> calls in a non-constructor context (i.e., without using the {{jsxref("Operators/new", "new")}} keyword) are primitive strings. JavaScript automatically converts primitives to <code>String</code> objects, so that it's possible to use <code>String</code> object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.</p> - -<pre class="brush: js">var s_prim = 'foo'; -var s_obj = new String(s_prim); - -console.log(typeof s_prim); // Logs "string" -console.log(typeof s_obj); // Logs "object" -</pre> - -<p>String primitives and <code>String</code> objects also give different results when using {{jsxref("Global_Objects/eval", "eval()")}}. Primitives passed to <code>eval</code> are treated as source code; <code>String</code> objects are treated as all other objects are, by returning the object. For example:</p> - -<pre class="brush: js">var s1 = '2 + 2'; // creates a string primitive -var s2 = new String('2 + 2'); // creates a String object -console.log(eval(s1)); // returns the number 4 -console.log(eval(s2)); // returns the string "2 + 2" -</pre> - -<p>For these reasons, code may break when it encounters <code>String</code> objects when it expects a primitive string instead, although generally authors need not worry about the distinction.</p> - -<p>A <code>String</code> object can always be converted to its primitive counterpart with the {{jsxref("String.prototype.valueOf()", "valueOf()")}} method.</p> - -<pre class="brush: js">console.log(eval(s2.valueOf())); // returns the number 4 -</pre> - -<div class="note"><strong>Note:</strong> For another possible approach to strings in JavaScript, please read the article about <a href="/en-US/Add-ons/Code_snippets/StringView"><code>StringView</code> — a C-like representation of strings based on typed arrays</a>.</div> - -<h2 id="Properties">Properties</h2> - -<dl> - <dt>{{jsxref("String.prototype")}}</dt> - <dd>Allows the addition of properties to a <code>String</code> object.</dd> -</dl> - -<h2 id="Methods">Methods</h2> - -<dl> - <dt>{{jsxref("String.fromCharCode()")}}</dt> - <dd>Returns a string created by using the specified sequence of Unicode values.</dd> - <dt>{{jsxref("String.fromCodePoint()")}} {{experimental_inline}}</dt> - <dd>Returns a string created by using the specified sequence of code points.</dd> - <dt>{{jsxref("String.raw()")}} {{experimental_inline}}</dt> - <dd>Returns a string created from a raw template string.</dd> -</dl> - -<h2 id="String_generic_methods"><code>String</code> generic methods</h2> - -<div class="warning"> -<p><strong>String generics are non-standard, deprecated and will get removed near future</strong>. Note that you can not rely on them cross-browser without using the shim that is provided below.</p> -</div> - -<p>The <code>String</code> instance methods are also available in Firefox as of JavaScript 1.6 (<strong>not</strong> part of the ECMAScript standard) on the <code>String</code> object for applying <code>String</code> methods to any object:</p> - -<pre class="brush: js">var num = 15; -console.log(String.replace(num, /5/, '2')); -</pre> - -<p>{{jsxref("Global_Objects/Array", "Generics", "#Array_generic_methods", 1)}} are also available on {{jsxref("Array")}} methods.</p> - -<p>The following is a shim to provide support to non-supporting browsers:</p> - -<pre class="brush: js">/*globals define*/ -// Assumes all supplied String instance methods already present -// (one may use shims for these if not available) -(function() { - 'use strict'; - - var i, - // We could also build the array of methods with the following, but the - // getOwnPropertyNames() method is non-shimable: - // Object.getOwnPropertyNames(String).filter(function(methodName) { - // return typeof String[methodName] === 'function'; - // }); - methods = [ - 'quote', 'substring', 'toLowerCase', 'toUpperCase', 'charAt', - 'charCodeAt', 'indexOf', 'lastIndexOf', 'startsWith', 'endsWith', - 'trim', 'trimLeft', 'trimRight', 'toLocaleLowerCase', - 'toLocaleUpperCase', 'localeCompare', 'match', 'search', - 'replace', 'split', 'substr', 'concat', 'slice' - ], - methodCount = methods.length, - assignStringGeneric = function(methodName) { - var method = String.prototype[methodName]; - String[methodName] = function(arg1) { - return method.apply(arg1, Array.prototype.slice.call(arguments, 1)); - }; - }; - - for (i = 0; i < methodCount; i++) { - assignStringGeneric(methods[i]); - } -}()); -</pre> - -<h2 id="String_instances"><code>String</code> instances</h2> - -<h3 id="Properties_2">Properties</h3> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Properties')}}</div> - -<h3 id="Methods_2">Methods</h3> - -<h4 id="Methods_unrelated_to_HTML">Methods unrelated to HTML</h4> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods_unrelated_to_HTML')}}</div> - -<h4 id="HTML_wrapper_methods">HTML wrapper methods</h4> - -<div>{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'HTML_wrapper_methods')}}</div> - -<h2 id="Examples">Examples</h2> - -<h3 id="String_conversion">String conversion</h3> - -<p>It's possible to use <code>String</code> as a "safer" {{jsxref("String.prototype.toString()", "toString()")}} alternative, as although it still normally calls the underlying <code>toString()</code>, it also works for {{jsxref("null")}} and {{jsxref("undefined")}}. For example:</p> - -<pre class="brush: js">var outputStrings = []; -for (var i = 0, n = inputValues.length; i < n; ++i) { - outputStrings.push(String(inputValues[i])); -} -</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-15.5', 'String')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string-objects', 'String')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string-objects', 'String')}}</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("1")}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td><code>\u{XXXXXX}</code></td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoDesktop("40")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</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> - <tr> - <td><code>\u{XXXXXX}</code></td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoMobile("40")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{domxref("DOMString")}}</li> - <li><a href="/en-US/Add-ons/Code_snippets/StringView"><code>StringView</code> — a C-like representation of strings based on typed arrays</a></li> - <li><a href="/en-US/docs/Web/API/DOMString/Binary">Binary strings</a></li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/string/indexof/index.html b/files/nl/web/javascript/reference/global_objects/string/indexof/index.html deleted file mode 100644 index efb0b0937f..0000000000 --- a/files/nl/web/javascript/reference/global_objects/string/indexof/index.html +++ /dev/null @@ -1,200 +0,0 @@ ---- -title: String.prototype.indexOf() -slug: Web/JavaScript/Reference/Global_Objects/String/indexOf -tags: - - JavaScript - - Method - - Prototype - - Reference - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf ---- -<div>{{JSRef}}</div> - -<p>De <strong><code>indexOf()</code></strong> methode geeft de positie van het eerste voorval van <code>searchValue</code> binnen het {{jsxref("String")}} object waarop het wordt aangeroepen, waarbij begonnen wordt met zoeken vanaf <code>fromIndex</code>. Geeft -1 terug als geen voorvallen van <code>searchValue </code>gevonden worden.</p> - -<h2 id="Syntaxis">Syntaxis</h2> - -<pre class="syntaxbox"><code><var>str</var>.indexOf(<var>searchValue</var>[, <var>fromIndex</var>]</code>)</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>searchValue</code></dt> - <dd>De string om naar te zoeken.</dd> - <dt><code>fromIndex</code> {{optional_inline}}</dt> - <dd>De index vanaf waar gezocht moet worden binnen de string. Dit kan elke integer zijn. De standaard waarde is <code>0</code>, waardoor de hele string wordt doorzocht. Als <code>fromIndex < 0</code> is wordt de hele string doorzocht. Als <code>fromIndex >= str.length</code> is wordt de string niet doorzocht en wordt -1 teruggegeven. (behalve als <code>searchValue</code> een lege string is, dan wordt <code>str.length</code> teruggegeven)</dd> -</dl> - -<h3 id="Return_waarde">Return waarde</h3> - -<p>De index waarop de gespecificeerde waarde het eerst voorkomt in de string; <strong>-1</strong> als die niet gevonden wordt.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>Karakters in een string zijn geïndexeerd van links naar rechts. De index van het eerste karakter is 0 en de index van het laatste karakter van een string genaamd <code>stringName</code> is <code>stringName.length - 1</code>.</p> - -<pre class="brush: js">'Blue Whale'.indexOf('Blue'); // geeft 0 terug -'Blue Whale'.indexOf('Blute'); // geeft -1 terug -'Blue Whale'.indexOf('Whale', 0); // geeft 5 terug -'Blue Whale'.indexOf('Whale', 5); // geeft 5 terug -'Blue Whale'.indexOf('', 9); // geeft 9 terug -'Blue Whale'.indexOf('', 10); // geeft 10 terug -'Blue Whale'.indexOf('', 11); // geeft 11 terug -</pre> - -<h3 id="Hoofdlettergevoeligheid">Hoofdlettergevoeligheid</h3> - -<p>De <code>indexOf()</code> methode is hoofdlettergevoelig. Het volgende voorbeeld geeft <code>-1</code> terug:</p> - -<pre class="brush: js">'Blue Whale'.indexOf('blue'); // geeft -1 terug -</pre> - -<h3 id="Voorvallen_controleren">Voorvallen controleren</h3> - -<p>Onthoudt dat '0' niet vertaalt naar <code>true</code> en '-1' niet vertaalt naar <code>false</code>. Hierdoor moet op de volgende manier gekeken worden of een string binnen een andere string zit:</p> - -<pre class="brush: js">'Blue Whale'.indexOf('Blue') !== -1; // true -'Blue Whale'.indexOf('Bloe') !== -1; // false -</pre> - -<h2 id="Examples">Examples</h2> - -<h3 id="indexOf()_en_lastIndexOf()_gebruiken"><code>indexOf()</code> en <code>lastIndexOf() gebruiken</code></h3> - -<p>Het volgende voorbeeld gebruikt <code>indexOf()</code> en {{jsxref("String.prototype.lastIndexOf()", "lastIndexOf()")}} om waardes binnen de string <code>"Brave new world" </code>te vinden.</p> - -<pre class="brush: js">var anyString = 'Brave new world'; - -console.log('De index van de eerste w vanaf het begin is ' + anyString.indexOf('w')); -// logs 8 -console.log('De index van de eerste w vanaf het begin is ' + anyString.lastIndexOf('w')); -// logs 10 - -console.log('De index van "new" vanaf het begin is ' + anyString.indexOf('new')); -// logs 6 -console.log('De index van "new" vanaf het eind is ' + anyString.lastIndexOf('new')); -// logs 6 -</pre> - -<h3 id="indexOf()_en_hoofdlettergevoeligheid"><code>indexOf()</code> en hoofdlettergevoeligheid</h3> - -<p>Het volgende voorbeeld legt twee string variabelen vast. Deze variabelen bevatten dezelfde string, behalve dat de tweede string hoofdletters bevat. De eerste {{domxref("console.log()")}} methode geeft <code>19</code> terug. Omdat de <code>indexOf()</code> methode hoofdlettergevoelig is, wordt de string <code>"cheddar"</code> niet gevonden in <code>myCapString</code>, dus de tweede <code>console.log()</code> methode geeft <code>-1</code> terug.</p> - -<pre class="brush: js">var myString = 'brie, pepper jack, cheddar'; -var myCapString = 'Brie, Pepper Jack, Cheddar'; - -console.log('myString.indexOf("cheddar") geeft ' + myString.indexOf('cheddar')); -// geeft 19 -console.log('myCapString.indexOf("cheddar") geeft ' + myCapString.indexOf('cheddar')); -// geeft -1 -</pre> - -<h3 id="indexOf()_gebruiken_om_voorvallen_van_een_letter_in_een_string_te_tellen"><code>indexOf()</code> gebruiken om voorvallen van een letter in een string te tellen</h3> - -<p>In het volgende voorbeeld wordt in <code>count</code> de hoeveelheid voorvallen van <code>e</code> in de string <code>str</code> bijgehouden:</p> - -<pre class="brush: js">var str = 'To be, or not to be, that is the question.'; -var count = 0; -var pos = str.indexOf('e'); - -while (pos !== -1) { - count++; - pos = str.indexOf('e', pos + 1); -} - -console.log(count); // geeft 4 -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Eerste definitie.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.5.4.7', 'String.prototype.indexOf')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</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>{{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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("String.prototype.charAt()")}}</li> - <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> - <li>{{jsxref("String.prototype.split()")}}</li> - <li>{{jsxref("Array.prototype.indexOf()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/string/startswith/index.html b/files/nl/web/javascript/reference/global_objects/string/startswith/index.html deleted file mode 100644 index b183929746..0000000000 --- a/files/nl/web/javascript/reference/global_objects/string/startswith/index.html +++ /dev/null @@ -1,96 +0,0 @@ ---- -title: String.prototype.startsWith() -slug: Web/JavaScript/Reference/Global_Objects/String/startsWith -tags: - - Begin - - JavaScript - - Méthode - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/startsWith ---- -<div>{{JSRef}}</div> - -<p><span class="seoSummary">De <strong><code>startsWith()</code></strong> methode bepaalt of een string begint met de karakters van een bepaalde string. Deze geeft <code>true</code> of <code>false</code> terug waar nodig.</span></p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><var>str</var>.startsWith(<em>zoek</em><var>String</var>[, <var>positie</var>])</pre> - -<h3 id="Parameters">Parameters</h3> - -<dl> - <dt><code>zoekString</code></dt> - <dd>De karakters om te zoeken aan het begin van de string.</dd> - <dt><code>positie</code>{{optional_inline}}</dt> - <dd>De positie in de string waar je start met zoeken naar <code>zoekString</code>; start standaard op 0.</dd> -</dl> - -<h3 id="Resultaat">Resultaat</h3> - -<p><strong><code>true</code></strong> als de karakters teruggevonden worden aan het begin van de string, anders <strong><code>false</code></strong>.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>Deze methde laat je nagaan of een string begint met een andere string. Dit is hoofdletter gevoelig</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Gebruik_startsWith()">Gebruik <code>startsWith()</code></h3> - -<pre class="brush: js">//startswith -var str = 'Te nemen of te laten.'; - -console.log(str.startsWith('Te nemen')); // true -console.log(str.startsWith('te laten')); // false -console.log(str.startsWith('te laten', 12)); // true -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>Deze methode is toegevoegd aan de ECMAScript 2015 specificaties en is misschien nog niet beschikbaar in alle JavaScript implementaties. Je kan wel Polyfill <code>String.prototype.startsWith()</code> alsvolgt gebruiken</p> - -<pre class="brush: js">if (!String.prototype.startsWith) { - String.prototype.startsWith = function(search, pos) { - return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search; - }; -} -</pre> - -<p>Een meer degelijke en geoptimaliseerde Polyfill is beschikbaar <a href="https://github.com/mathiasbynens/String.prototype.startsWith">op GitHub door Mathias Bynens</a>.</p> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Commentaar</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Eerste definitie.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.startswith', 'String.prototype.startsWith')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibiliteit">Browser compatibiliteit</h2> - -<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> - -<p>{{Compat("javascript.builtins.String.startsWith")}}</p> - -<h2 id="Meer_lezen">Meer lezen</h2> - -<ul> - <li>{{jsxref("String.prototype.endsWith()")}}</li> - <li>{{jsxref("String.prototype.includes()")}}</li> - <li>{{jsxref("String.prototype.indexOf()")}}</li> - <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html b/files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html deleted file mode 100644 index 4716e5afa5..0000000000 --- a/files/nl/web/javascript/reference/global_objects/string/tolowercase/index.html +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: String.prototype.toLowerCase() -slug: Web/JavaScript/Reference/Global_Objects/String/toLowerCase -tags: - - JavaScript - - Method - - Prototype - - Reference - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/toLowerCase ---- -<div>{{JSRef}}</div> - -<p>De <strong><code>toLowerCase()</code></strong> methode geeft een string terug waarbij de meegegeven string naar kleine letters is geconverteerd.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>str</var>.toLowerCase()</code></pre> - -<h3 id="Returnwaarde">Returnwaarde</h3> - -<p>Een nieuwe string waarbij de meegegeven string naar kleine letters is geconverteerd.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De <code>toLowerCase()</code> methode geeft een string terug waarbij de meegegeven string naar kleine letters is geconverteerd. <code>toLowerCase()</code> past de waarde van de meegegeven string <code>str</code> niet aan.</p> - -<h2 id="Examples">Examples</h2> - -<h3 id="Gebruik_van_toLowerCase()">Gebruik van <code>toLowerCase()</code></h3> - -<pre class="brush: js">console.log('ALFABET'.toLowerCase()); // 'alfabet' -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initiële definitie. Geïmplementeerd in JavaScript 1.0.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.5.4.16', 'String.prototype.toLowerCase')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.tolowercase', 'String.prototype.toLowerCase')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browsercompatibiliteit">Browsercompatibiliteit</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>Basisondersteuning</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>Basisondersteuning</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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("String.prototype.toLocaleLowerCase()")}}</li> - <li>{{jsxref("String.prototype.toLocaleUpperCase()")}}</li> - <li>{{jsxref("String.prototype.toUpperCase()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/string/touppercase/index.html b/files/nl/web/javascript/reference/global_objects/string/touppercase/index.html deleted file mode 100644 index 32393e3c86..0000000000 --- a/files/nl/web/javascript/reference/global_objects/string/touppercase/index.html +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: String.prototype.toUpperCase() -slug: Web/JavaScript/Reference/Global_Objects/String/toUpperCase -tags: - - JavaScript - - Method - - Prototype - - Reference - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/toUpperCase ---- -<div>{{JSRef}}</div> - -<p>De <strong><code>toUpperCase()</code></strong> methode geeft een string terug waarbij de meegegeven string naar hoofdletters is geconverteerd.</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>str</var>.toUpperCase()</code></pre> - -<h3 id="Returnwaarde">Returnwaarde</h3> - -<p>Een nieuwe string waarbij de meegegeven string naar hoofdletters is geconverteerd.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De <code>toUpperCase()</code> methode geeft een string terug waarbij de meegegeven string naar hoofdletters is geconverteerd.. <code>toUpperCase()</code> past de waarde van de meegegeven string niet aan.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Gebruik_van_toUpperCase()">Gebruik van <code>toUpperCase()</code></h3> - -<pre class="brush: js">console.log('alfabet'.toUpperCase()); // 'ALFABET' -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initiële definitie. Geïmplementeerd in JavaScript 1.0.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.5.4.18', 'String.prototype.toUpperCase')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.touppercase', 'String.prototype.toUpperCase')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browsercompatibiliteit">Browsercompatibiliteit</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>Basisondersteuning</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>Basisondersteuning</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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("String.prototype.toLocaleLowerCase()")}}</li> - <li>{{jsxref("String.prototype.toLocaleUpperCase()")}}</li> - <li>{{jsxref("String.prototype.toLowerCase()")}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/string/trim/index.html b/files/nl/web/javascript/reference/global_objects/string/trim/index.html deleted file mode 100644 index c595279b0d..0000000000 --- a/files/nl/web/javascript/reference/global_objects/string/trim/index.html +++ /dev/null @@ -1,139 +0,0 @@ ---- -title: String.prototype.trim() -slug: Web/JavaScript/Reference/Global_Objects/String/Trim -tags: - - ECMAScript6 - - JavaScript - - Method - - Prototype - - Reference - - String -translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim ---- -<div>{{JSRef}}</div> - -<p>De <strong><code>trim()</code></strong> methode verwijdert witruimte aan het begin en einde van een string. Witruimte betreft in deze context alle whitespace karakters (spatie, tab, no-break spatie, etc.) en alle regeleindekarakters (LF, CR, etc.).</p> - -<h2 id="Syntax">Syntax</h2> - -<pre class="syntaxbox"><code><var>str</var>.trim()</code></pre> - -<h3 id="Returnwaarde">Returnwaarde</h3> - -<p>Een nieuwe string waarbij de meegegeven string geen witruimte aan beide kanten meer heeft.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>De <code>trim()</code> methode geeft een string terug waarvan aan het begin en einde de witruimte is afgestript. <code>trim()</code> past de waarde van de string zelf niet aan.</p> - -<h2 id="Voorbeelden">Voorbeelden</h2> - -<h3 id="Het_gebruik_van_trim()">Het gebruik van <code>trim()</code></h3> - -<p>Het volgende voorbeeld toont de string <code>'foo'</code>:</p> - -<pre class="brush: js">var orig = ' foo '; -console.log(orig.trim()); // 'foo' - -// Ander voorbeeld .trim() voor het verwijderen van witruimte aan een kant. - -var orig = 'foo '; -console.log(orig.trim()); // 'foo' -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>Roep de volgende code aan voor het aanroepen van andere code, om <code>trim()</code> beschikbaar te maken als deze nog niet oorspronkelijk ondersteund werd.</p> - -<pre class="brush: js">if (!String.prototype.trim) { - String.prototype.trim = function () { - return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); - }; -} -</pre> - -<h2 id="Specificaties">Specificaties</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificatie</th> - <th scope="col">Status</th> - <th scope="col">Opmerking</th> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.5.4.20', 'String.prototype.trim')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>Initiële definitie. Geïmplementeerd in JavaScript 1.8.1.</td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string.prototype.trim', 'String.prototype.trim')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.trim', 'String.prototype.trim')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browsercompatibiliteit">Browsercompatibiliteit</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>Basisondersteuning</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("1.9.1")}}</td> - <td>{{CompatIE("9")}}</td> - <td>{{CompatOpera("10.5")}}</td> - <td>{{CompatSafari("5")}}</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>Basisondersteuning</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="Zie_ook">Zie ook</h2> - -<ul> - <li>{{jsxref("String.prototype.trimLeft()")}} {{non-standard_inline}}</li> - <li>{{jsxref("String.prototype.trimRight()")}} {{non-standard_inline}}</li> -</ul> diff --git a/files/nl/web/javascript/reference/global_objects/symbol/index.html b/files/nl/web/javascript/reference/global_objects/symbol/index.html deleted file mode 100644 index cca76311f1..0000000000 --- a/files/nl/web/javascript/reference/global_objects/symbol/index.html +++ /dev/null @@ -1,206 +0,0 @@ ---- -title: Symbool -slug: Web/JavaScript/Reference/Global_Objects/Symbol -tags: - - ECMAScript 2015 - - JavaScript - - Klasse - - Symbool -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol -original_slug: Web/JavaScript/Reference/Global_Objects/Symbool ---- -<div>{{JSRef}}</div> - -<p>Het gegevenstype symbool is een <a href="https://wiki.developer.mozilla.org/en-US/docs/Glossary/Primitive">primitief gegevenstype</a>. De Symbol() functie geeft een waarde terug <em>(returns a value)</em> van het type symbool, heeft statische eigenschappen die verscheidene leden van ingebouwde objecten blootstelt, heeft statische methoden die het globale symbolregister blootstellen en vertegenwoordigd een ingebouwde objectklasse. Maar is onvolledig als een constructor, omdat het niet de "new Symbol()" syntaxis ondersteund.</p> - -<p>Elke waarde teruggekregen van Symbol() is uniek. Zo'n teruggekregen waarde kan, bijvoorbeeld, gebruikt worden als identificatiemiddel voor objecteigenschappen; het primaire doel van dit gegevenstype. Hoewel er andere use-cases zijn, zoals het beschikbaar maken van ondoorzichtige gegevenstypen of als algemeen uniek identificatiemiddel. Meer uitleg over het doel en gebruik van het symbool is te vinden in de woordenlijst.</p> - -<h2 id="Beschrijving">Beschrijving</h2> - -<p>Om een nieuw primitief symbool te creëren, schrijf je <code>Symbol()</code> met een optionele <a href="/en-US/docs/Web/CSS/string">String</a> als beschrijving:</p> - -<pre class="brush: js">let sym1 = Symbol() -let sym2 = Symbol('foo') -let sym3 = Symbol('foo') -</pre> - -<p>De bovenstaande code creëert drie nieuwe symbolen. Let er op dat <code>Symbol("foo")</code> niet de string <code>"foo"</code> omzet naar een symbool maar dat het telkens een nieuw uniek symbool creëert:</p> - -<pre class="brush: js">Symbol('foo') === Symbol('foo') // false -</pre> - -<p>De volgende syntaxis met de {{jsxref("Operators/new", "new")}} operator zal een {{jsxref("TypeError")}}: afwerpen:</p> - -<pre class="brush: js">let sym = new Symbol() // TypeError -</pre> - -<p>Dit behoed auteurs ervoor om nadrukkelijk een <code>Symbol</code> wrapper-object te creëren in plaats van een nieuwe symboolwaarde. Terwijl normaal gesproken primitieve gegevenstypen wel gemaakt kunnen worden met een wrapper-object. (Zoals: <code>new Boolean</code>, <code>new String</code> en <code>new Number</code>).</p> - -<p>Als je echt een <code>Symbol</code> wrapper-object wilt maken, kun je dit doen met de <code>Object()</code> functie:</p> - -<pre class="brush: js">let sym = Symbol('foo') -typeof sym // "symbol" -let symObj = Object(sym) -typeof symObj // "object" -</pre> - -<h3 id="Gedeelde_symbolen_in_het_globale_symboolregister">Gedeelde symbolen in het globale symboolregister</h3> - -<p>De bovenstaande syntaxis, die gebruik maakt van de <code>Symbol()</code> functie, creëert alleen niet een globaal symbool dat te gebruiken is door je gehele codebase. Om symbolen te creëren die door al je bestanden en zelfs door je <em>realms</em> (met elk hun eigen globale<em> scope</em>) te gebruiken zijn; gebruik je de methoden {{jsxref("Symbol.for()")}} en {{jsxref("Symbol.keyFor()")}}. Om, respectievelijk<strong>, </strong>symbolen in het globale symbolenregister aan te maken en terug te krijgen.</p> - -<h3 id="Symbooleigenschappen_vinden_in_objecten">Symbooleigenschappen vinden in objecten</h3> - -<p>De methode {{jsxref("Object.getOwnPropertySymbols()")}} geeft een array met symbolen terug en laat je symbooleigenschappen vinden in een opgegeven object. Let er op dat elk object geïnitialiseerd wordt zonder eigen symbooleigenschappen, dus deze array zal leeg zijn tenzij je een symbool als eigenschap hebt gegeven aan een object. </p> - -<h2 id="Constructor">Constructor</h2> - -<dl> - <dt><code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/Symbol">Symbol()</a></code></dt> - <dd>De <code>Symbol()</code> constructor geeft een waarde terug van het type <strong>symbol</strong>, maar is incompleet als een constructor omdat het niet de "<code>new Symbol()</code>" syntaxis ondersteund.</dd> -</dl> - -<h2 id="Static_properties">Static properties</h2> - -<dl> - <dt>{{jsxref("Symbol.asyncIterator")}}</dt> - <dd>A method that returns the default AsyncIterator for an object. Used by <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of"><code>for await...of</code></a>.</dd> - <dt>{{jsxref("Symbol.hasInstance")}}</dt> - <dd>A method determining if a constructor object recognizes an object as its instance. Used by {{jsxref("Operators/instanceof", "instanceof")}}.</dd> - <dt>{{jsxref("Symbol.isConcatSpreadable")}}</dt> - <dd>A Boolean value indicating if an object should be flattened to its array elements. Used by {{jsxref("Array.prototype.concat()")}}.</dd> - <dt>{{jsxref("Symbol.iterator")}}</dt> - <dd>A method returning the default iterator for an object. Used by <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of"><code>for...of</code></a>.</dd> - <dt>{{jsxref("Symbol.match")}}</dt> - <dd>A method that matches against a string, also used to determine if an object may be used as a regular expression. Used by {{jsxref("String.prototype.match()")}}.</dd> - <dt>{{jsxref("Symbol.matchAll")}}</dt> - <dd>A method that returns an iterator, that yields matches of the regular expression against a string. Used by {{jsxref("String.prototype.matchAll()")}}.</dd> - <dt>{{jsxref("Symbol.replace")}}</dt> - <dd>A method that replaces matched substrings of a string. Used by {{jsxref("String.prototype.replace()")}}.</dd> - <dt>{{jsxref("Symbol.search")}}</dt> - <dd>A method that returns the index within a string that matches the regular expression. Used by {{jsxref("String.prototype.search()")}}.</dd> - <dt>{{jsxref("Symbol.split")}}</dt> - <dd>A method that splits a string at the indices that match a regular expression. Used by {{jsxref("String.prototype.split()")}}.</dd> - <dt>{{jsxref("Symbol.species")}}</dt> - <dd>A constructor function that is used to create derived objects.</dd> - <dt>{{jsxref("Symbol.toPrimitive")}}</dt> - <dd>A method converting an object to a primitive value.</dd> - <dt>{{jsxref("Symbol.toStringTag")}}</dt> - <dd>A string value used for the default description of an object. Used by {{jsxref("Object.prototype.toString()")}}.</dd> - <dt>{{jsxref("Symbol.unscopables")}}</dt> - <dd>An object value of whose own and inherited property names are excluded from the <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/with">with</a></code> environment bindings of the associated object.</dd> -</dl> - -<h2 id="Static_methods">Static methods</h2> - -<dl> - <dt>{{jsxref("Symbol.for()", "Symbol.for(key)")}}</dt> - <dd>Searches for existing symbols with the given <code><var>key</var></code> and returns it if found. Otherwise a new symbol gets created in the global symbol registry with <code><var>key</var></code>.</dd> - <dt>{{jsxref("Symbol.keyFor", "Symbol.keyFor(sym)")}}</dt> - <dd>Retrieves a shared symbol key from the global symbol registry for the given symbol.</dd> -</dl> - -<h2 id="Instance_properties">Instance properties</h2> - -<dl> - <dt>{{jsxref("Symbol.prototype.description")}}</dt> - <dd>A read-only string containing the description of the symbol.</dd> -</dl> - -<h2 id="Instance_methods">Instance methods</h2> - -<dl> - <dt>{{jsxref("Symbol.prototype.toSource()")}}</dt> - <dd>Returns a string containing the source of the {{jsxref("Global_Objects/Symbol", "Symbol")}} object. Overrides the {{jsxref("Object.prototype.toSource()")}} method.</dd> - <dt>{{jsxref("Symbol.prototype.toString()")}}</dt> - <dd>Returns a string containing the description of the Symbol. Overrides the {{jsxref("Object.prototype.toString()")}} method.</dd> - <dt>{{jsxref("Symbol.prototype.valueOf()")}}</dt> - <dd>Returns the primitive value of the {{jsxref("Symbol")}} object. Overrides the {{jsxref("Object.prototype.valueOf()")}} method.</dd> - <dt>{{jsxref("Symbol.prototype.@@toPrimitive()", "Symbol.prototype[@@toPrimitive]")}}</dt> - <dd>Returns the primitive value of the {{jsxref("Symbol")}} object.</dd> -</dl> - -<h2 id="Examples">Examples</h2> - -<h3 id="Using_the_typeof_operator_with_symbols">Using the typeof operator with symbols</h3> - -<p>The {{jsxref("Operators/typeof", "typeof")}} operator can help you to identify symbols.</p> - -<pre class="brush: js">typeof Symbol() === 'symbol' -typeof Symbol('foo') === 'symbol' -typeof Symbol.iterator === 'symbol' -</pre> - -<h3 id="Symbol_type_conversions">Symbol type conversions</h3> - -<p>Some things to note when working with type conversion of symbols.</p> - -<ul> - <li>When trying to convert a symbol to a number, a {{jsxref("TypeError")}} will be thrown<br> - (e.g. <code>+<var>sym</var></code> or <code><var>sym</var> | 0</code>).</li> - <li>When using loose equality, <code>Object(<var>sym</var>) == <var>sym</var></code> returns <code>true</code>.</li> - <li><code>Symbol("foo") + "bar" </code>throws a {{jsxref("TypeError")}} (can't convert symbol to string). This prevents you from silently creating a new string property name from a symbol, for example.</li> - <li>The <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_conversion">"safer" <code>String(<var>sym</var>)</code> conversion</a> works like a call to {{jsxref("Symbol.prototype.toString()")}} with symbols, but note that <code>new String(<var>sym</var>)</code> will throw.</li> -</ul> - -<h3 id="Symbols_and_for...in_iteration">Symbols and for...in iteration</h3> - -<p>Symbols are not enumerable in <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for...in</code></a> iterations. In addition, {{jsxref("Object.getOwnPropertyNames()")}} will not return symbol object properties, however, you can use {{jsxref("Object.getOwnPropertySymbols()")}} to get these.</p> - -<pre class="brush: js">let obj = {} - -obj[Symbol('a')] = 'a' -obj[Symbol.for('b')] = 'b' -obj['c'] = 'c' -obj.d = 'd' - -for (let i in obj) { - console.log(i) // logs "c" and "d" -}</pre> - -<h3 id="Symbols_and_JSON.stringify">Symbols and JSON.stringify()</h3> - -<p>Symbol-keyed properties will be completely ignored when using <code>JSON.stringify()</code>:</p> - -<pre class="brush: js">JSON.stringify({[Symbol('foo')]: 'foo'}) -// '{}' -</pre> - -<p>For more details, see {{jsxref("JSON.stringify()")}}.</p> - -<h3 id="Symbol_wrapper_objects_as_property_keys">Symbol wrapper objects as property keys</h3> - -<p>When a Symbol wrapper object is used as a property key, this object will be coerced to its wrapped symbol:</p> - -<pre class="brush: js">let sym = Symbol('foo') -let obj = {[sym]: 1} -obj[sym] // 1 -obj[Object(sym)] // still 1 -</pre> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-symbol-objects', 'Symbol')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - - - -<p>{{Compat("javascript.builtins.Symbol")}}</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Glossary/Symbol">Glossary: Symbol data type</a></li> - <li>{{jsxref("Operators/typeof", "typeof")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Data_structures">Data types and data structures</a></li> - <li><a href="https://hacks.mozilla.org/2015/06/es6-in-depth-symbols/">"ES6 In Depth: Symbols" on hacks.mozilla.org</a></li> -</ul> |