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/it/web/javascript/reference/global_objects/string | |
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/it/web/javascript/reference/global_objects/string')
6 files changed, 0 insertions, 1194 deletions
diff --git a/files/it/web/javascript/reference/global_objects/string/charat/index.html b/files/it/web/javascript/reference/global_objects/string/charat/index.html deleted file mode 100644 index 312cfa9713..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/charat/index.html +++ /dev/null @@ -1,247 +0,0 @@ ---- -title: String.prototype.charAt() -slug: Web/JavaScript/Reference/Global_Objects/String/charAt -translation_of: Web/JavaScript/Reference/Global_Objects/String/charAt ---- -<div>{{JSRef}}</div> - -<p><span class="seoSummary">Il metodo {{jsxref("String")}} dell'oggetto <strong><code>charAt()</code></strong> restituisce una nuova stringa che consiste nella singola unità di codice UTF-16 situata nell'offset specificato nella stringa.</span></p> - -<div>{{EmbedInteractiveExample("pages/js/string-charat.html")}}</div> - -<p class="hidden">La fonte per questo esempio interattivo è memorizzata in un repository GitHub. Se desideri contribuire al progetto di esempi interattivi, clonare <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> e inviarci una richiesta di pull.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><em>carattere</em> = <em>str</em>.charAt(<em>indice</em>)</pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>index</code></dt> - <dd>Un numero intero compreso tra 0 e 1-meno della lunghezza della stringa. Se non viene fornito alcun indice, il valore predefinito è 0, quindi viene restituito il primo carattere nella stringa.</dd> -</dl> - -<h3 id="Valore_restituito">Valore restituito</h3> - -<p>Una stringa che rappresenta il carattere (esattamente un'unità di codice UTF-16) nell'indice specificato; stringa vuota se <code>index</code> non è compreso nell'intervallo</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>I caratteri in una stringa sono indicizzati da sinistra a destra. L'indice del primo carattere è 0 e l'indice dell'ultimo carattere in una stringa chiamata <code>stringName</code> è <code>stringName.length - 1</code>. Se l'indice che fornisci è fuori da questo intervallo, JavaScript restituisce una stringa vuota.</p> - -<p>Se non viene fornito alcun indice per <code> charAt()</code>, il valore predefinito è 0.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Visualizzazione_di_caratteri_in_posizioni_diverse_in_una_stringa">Visualizzazione di caratteri in posizioni diverse in una stringa</h3> - -<p>Nell'esempio seguente vengono visualizzati caratteri in posizioni diverse nella stringa <code> "Brave new world"</code>:</p> - -<pre class="brush: js">var anyString = 'Brave new world'; -console.log("Il carattere nell'indice 0 è '" + anyString.charAt() + "'"); -// Non è stato fornito alcun indice, usato 0 come predefinito - -console.log("The character at index 0 is '" + anyString.charAt(0) + "'"); -console.log("The character at index 1 is '" + anyString.charAt(1) + "'"); -console.log("The character at index 2 is '" + anyString.charAt(2) + "'"); -console.log("The character at index 3 is '" + anyString.charAt(3) + "'"); -console.log("The character at index 4 is '" + anyString.charAt(4) + "'"); -console.log("The character at index 999 is '" + anyString.charAt(999) + "'"); -</pre> - -<p>Queste righe mostrano quanto segue:</p> - -<pre class="brush: js">//Il carattere nell'indice 0 is 'B' - -//Il carattere nell'indice 0 is 'B' -//Il carattere nell'indice 1 is 'r' -//Il carattere nell'indice 2 is 'a' -//Il carattere nell'indice 3 is 'v' -//Il carattere nell'indice 4 is 'e' -//Il carattere nell'indice 999 is '' -</pre> - -<h3 id="Recupero_di_caratteri_interi">Recupero di caratteri interi</h3> - -<p>Quanto segue fornisce un mezzo per garantire che l'attraversamento di un loop string fornisca sempre un intero carattere, anche se la stringa contiene caratteri che non si trovano nel piano multi-lingue di base.</p> - -<pre class="brush: js">var str = 'A \uD87E\uDC04 Z'; // Potremmo anche usare direttamente un carattere non-BMP -for (var i = 0, chr; i < str.length; i++) { - if ((chr = getWholeChar(str, i)) === false) { - continue; - } - // Adatta questa linea all'inizio di ogni ciclo, passando l'intera stringa e - // l'iterazione corrente e il ritorno di una variabile per rappresentare il - // personaggio individuale - - console.log(chr); -} - -function getWholeChar(str, i) { - var code = str.charCodeAt(i); - - if (Number.isNaN(code)) { - return ''; // Posizione non trovata - } - if (code < 0xD800 || code > 0xDFFF) { - return str.charAt(i); - } - - // Alto surrogato (potrebbe cambiare l'ultimo esadecimale a 0xDB7F per trattare un alto privato - // si surroga come singoli caratteri) - if (0xD800 <= code && code <= 0xDBFF) { - if (str.length <= (i + 1)) { - throw 'Alto surrogato senza seguire un surrogato basso'; - } - var next = str.charCodeAt(i + 1); - if (0xDC00 > next || next > 0xDFFF) { - throw 'Alto surrogato senza seguire un surrogato basso'; - } - return str.charAt(i) + str.charAt(i + 1); - } - // Low surrogate (0xDC00 <= code && code <= 0xDFFF) - if (i === 0) { - throw 'Basso surrogato senza precedente surrogato elevato'; - } - var prev = str.charCodeAt(i - 1); - - // (could change last hex to 0xDB7F to treat high private - // surrogates as single characters) - if (0xD800 > prev || prev > 0xDBFF) { - throw 'Basso surrogato senza precedente surrogato elevato'; - } - // Ora possiamo passare sopra surrogati bassi come secondo componente - // in una coppia che abbiamo già elaborato - return false; -} -</pre> - -<p>In un ambiente ECMAScript 2016 che consente l'assegnazione destrutturata, la seguente è un'alternativa più succinta e un po 'più flessibile in quanto incrementa automaticamente una variabile incrementale (se il carattere lo richiede in quanto coppia surrogata).</p> - -<pre class="brush: js">var str = 'A\uD87E\uDC04Z'; // Potremmo anche usare direttamente un carattere non-BMP -for (var i = 0, chr; i < str.length; i++) { - [chr, i] = getWholeCharAndI(str, i); - // Adatta questa linea all'inizio di ogni ciclo, passando l'intera stringa e - // l'iterazione corrente e la restituzione di un array con il singolo carattere - // e valore "i" (modificato solo se una coppia surrogata) - - console.log(chr); -} -function getWholeCharAndI(str, i) { - var code = str.charCodeAt(i); - if (Number.isNaN(code)) { - return ''; // Posizione non trovata - } - if (code < 0xD800 || code > 0xDFFF) { - return [str.charAt(i), i]; // Carattere normale, mantenendo 'i' lo stesso - } - // Alto surrogato (potrebbe cambiare l'ultimo esadecimale a 0xDB7F per trattare un alto privato - // si surroga come singoli caratteri) - if (0xD800 <= code && code <= 0xDBFF) { - if (str.length <= (i + 1)) { - throw "Alto surrogato senza seguire un surrogato basso"; - } - var next = str.charCodeAt(i + 1); - if (0xDC00 > next || next > 0xDFFF) { - throw "Alto surrogato senza seguire un surrogato basso"; - } - return [str.charAt (i) + str.charAt (i + 1), i + 1]; - } - // Basso surrogato (0xDC00 <= code && code <= 0xDFFF) - if (i === 0) { - throw "Basso surrogato senza precedente surrogato elevato"; - } - var prev = str.charCodeAt(i - 1); - // (potrebbe cambiare l'ultimo esadecimale in 0xDB7F per trattare i surrogati ad alto livello privato - // come singoli caratteri) - if (0xD800 > prev || prev > 0xDBFF) { - throw "Basso surrogato senza precedente surrogato elevato"; - } - // Restituisce invece il carattere successivo (e incrementa) - return [str.charAt(i + 1), i + 1]; -} -</pre> - -<h3 id="Correggere_charAt()_per_supportare_caratteri_non-Basic-Multilingual-Plane_(BMP)">Correggere <code>charAt()</code> per supportare caratteri non-Basic-Multilingual-Plane (BMP)</h3> - -<p>Mentre l'esempio sopra può essere più frequentemente utile per coloro che desiderano supportare caratteri non BMP (dal momento che non richiede al chiamante di sapere dove potrebbe apparire un personaggio non BMP), nel caso in cui uno lo desideri, nella scelta di un personaggio per indice, per trattare le coppie surrogate all'interno di una stringa come i singoli caratteri che rappresentano, si può usare quanto segue:</p> - -<pre class="brush: js">function fixedCharAt(str, idx) { - var ret = ''; - str += ''; - var end = str.length; - - var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; - while ((surrogatePairs.exec(str)) != null) { - var li = surrogatePairs.lastIndex; - if (li - 2 < idx) { - idx++; - } else { - break; - } - } - - if (idx >= end || idx < 0) { - return ''; - } - - ret += str.charAt(idx); - - if (/[\uD800-\uDBFF]/.test(ret) && /[\uDC00-\uDFFF]/.test(str.charAt(idx + 1))) { - // Vai avanti, poiché uno dei "personaggi" fa parte di una coppia di sostituti - ret += str.charAt(idx + 1); - } - return ret; -} -</pre> - -<h2 id="Specificazioni">Specificazioni</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificazioni</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>definizione iniziale.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.5.4.4', 'String.prototype.charAt')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string.prototype.charat', 'String.prototype.charAt')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.charat', 'String.prototype.charAt')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_il_browser">Compatibilità con il browser</h2> - -<p class="hidden">La tabella di compatibilità in questa pagina è generata da dati strutturati. Se desideri contribuire ai dati, consulta <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> e inviaci una richiesta di pull.</p> - -<p>{{Compat("javascript.builtins.String.charAt")}}</p> - -<h2 id="Guarda_anche">Guarda anche</h2> - -<ul> - <li>{{jsxref("String.prototype.indexOf()")}}</li> - <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> - <li>{{jsxref("String.prototype.charCodeAt()")}}</li> - <li>{{jsxref("String.prototype.codePointAt()")}}</li> - <li>{{jsxref("String.prototype.split()")}}</li> - <li>{{jsxref("String.fromCodePoint()")}}</li> - <li><a href="https://mathiasbynens.be/notes/javascript-unicode">JavaScript has a Unicode problem – Mathias Bynens</a></li> -</ul> diff --git a/files/it/web/javascript/reference/global_objects/string/includes/index.html b/files/it/web/javascript/reference/global_objects/string/includes/index.html deleted file mode 100644 index 44eac8fc22..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/includes/index.html +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: String.prototype.includes() -slug: Web/JavaScript/Reference/Global_Objects/String/includes -translation_of: Web/JavaScript/Reference/Global_Objects/String/includes ---- -<div>{{JSRef}}</div> - -<div>Il metodo <strong><code>includes() </code></strong>verifica se una stringa ne contiene un'altra desiderata, restituendo <code>true</code> o <code>false</code> in base dell'esito della ricerca.</div> - -<div> </div> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code><var>str</var>.includes(<var>searchString</var>[, <var>position</var>])</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>searchString</code></dt> - <dd>Una stringa da cercare all'interno di una stringa.</dd> - <dt><code>position</code></dt> - <dd>Opzionale. La posizione in questa stringa. La posizione in questa stringa in cui iniziare la ricerca di searchString; il valore predefinito è 0.</dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p><strong><code>true</code></strong> se la stringa contiene la stringa di ricerca; altrimenti, <strong><code>false</code></strong>.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Questo metodo permette di determinare se la stringa includa o no un'altra stringa.</p> - -<h3 id="Sensitività_alle_maiuscole">Sensitività alle maiuscole</h3> - -<p>Il metodo <code>includes()</code> è sensibile alle maiuscole. Per esempio, la seguente espressione restituisce false:</p> - -<pre class="brush: js">'Blue Whale'.includes('blue'); // returns false -</pre> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Utilizzando_includes()">Utilizzando <code>includes()</code></h3> - -<pre class="brush: js">var str = 'To be, or not to be, that is the question.'; - -console.log(str.includes('To be')); // true -console.log(str.includes('question')); // true -console.log(str.includes('nonexistent')); // false -console.log(str.includes('To be', 1)); // false -console.log(str.includes('TO BE')); // false -</pre> - -<h2 id="Polyfill">Polyfill</h2> - -<p>Questo metodo è stato aggiunto alla specifica ECMAScript 2015 e potrebbe essere non disponibile ancora in tutte le implementazioni di JavaScript.</p> - -<pre class="brush: js">if (!String.prototype.includes) { - String.prototype.includes = function(search, start) { - 'use strict'; - if (typeof start !== 'number') { - start = 0; - } - - if (start + search.length > this.length) { - return false; - } else { - return this.indexOf(search, start) !== -1; - } - }; -} - -/* -https://github.com/FabioVergani/js-Polyfill_StringIncludes/blob/master/StringIncludes.js - -(function(s){'use strict'; - var o=s.prototype,p='includes'; - o[p]||(o[p]=function(a,b){//search,start - var e=this,i=isNaN(b)?0:b,t=a,l=t.length; - return (l<1||((i+l)>e.length))?false:-1!==e.indexOf(t,i); - }); -})(String); - -*/</pre> - -<p> </p> - -<p> </p> - -<p> </p> - -<p> </p> - -<h2 id="Specificazioni">Specificazioni</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-string.prototype.includes', 'String.prototype.includes')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Definizioni inizili.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.includes', 'String.prototype.includes')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_Browser">Compatibilità Browser </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>{{CompatChrome("41")}}</td> - <td>{{CompatGeckoDesktop("40")}}</td> - <td>{{CompatNo}}</td> - <td>14393+</td> - <td>{{CompatNo}}</td> - <td>{{CompatSafari("9")}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatGeckoMobile("40")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="String.prototype.contains">String.prototype.contains</h2> - -<p>In Firefox 18 - 39, il nome di questo metodo era <code>contains()</code>. E' stato rinominato in<code>includes()</code> in {{bug(1102219)}} a causa del seguente motivo:</p> - -<p>E' stato riportato che alcuni websites che utilizzano MooTools 1.2 non funzionavano su Firefox 17. Tale versione di MooTools controlla se <code>String.prototype.contains()</code> esiste e, se non esiste, MooTools aggiunge una propria funzione. Con l'introduzione di questa funzione in Firefox 17, il comportamento di tale controllo è cambiato in un modo che il codice basato su <code>String.prototype.contains()</code> non funzioni. Come risultato, l'implementazione è stata disabilitata in Firefox 17 e <code>String.prototype.contains()</code> era disponibile nella versione successiva, in Firefox 18, quando <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=789036#c32">outreach to MooTools </a>stava conducendo al rilascio di <a href="http://mootools.net/blog/2013/02/19/mootools-1-2-6-released">MooTools version 1.2.6</a>.</p> - -<p>MooTools 1.3 forza la propria versione di <code>String.prototype.contains()</code>, così i siti web che si affidano ad essa non vanno in break. Comunque si noti che la signature di <a href="http://mootools.net/core/docs/1.3.2/Types/String#String-method:-contains">MooTools 1.3 </a>e quella di ECMAScript 2015 per questo metodo differiscono (sul secondo argomento). Più avanti , <a href="https://github.com/mootools/mootools-core/blob/master/Docs/Types/String.md#note">MooTools 1.5+ ha cambiato la signature per incontrare lo standard ES2015.</a></p> - -<p>In Firefox 48, <code>String.prototype.contains()</code> è stato rimosso. Usare <code>String.prototype.includes()</code> solamente.</p> - -<h2 id="Vedere_anche">Vedere anche</h2> - -<ul> - <li>{{jsxref("Array.prototype.includes()")}} {{experimental_inline}}</li> - <li>{{jsxref("TypedArray.prototype.includes()")}} {{experimental_inline}}</li> - <li>{{jsxref("String.prototype.indexOf()")}}</li> - <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> - <li>{{jsxref("String.prototype.startsWith()")}}</li> - <li>{{jsxref("String.prototype.endsWith()")}}</li> -</ul> diff --git a/files/it/web/javascript/reference/global_objects/string/index.html b/files/it/web/javascript/reference/global_objects/string/index.html deleted file mode 100644 index 713f9a0cb4..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/index.html +++ /dev/null @@ -1,410 +0,0 @@ ---- -title: String -slug: Web/JavaScript/Reference/Global_Objects/String -tags: - - ECMAScript 2015 - - JavaScript - - NeedsTranslation - - Reference - - String - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/String ---- -<div>{{JSRef}}</div> - -<p>L'oggetto globale "String" è un costruttore per le stringhe o una sequenza alfanumerica di caratteri.</p> - -<h2 id="Syntax">Syntax</h2> - -<p>String literals take the forms:</p> - -<pre class="syntaxbox">'string text' -"string text" -"中文 español deutsch English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ் עברית"</pre> - -<p>Strings can also be created using the <code>String</code> global object directly:</p> - -<pre class="syntaxbox">String(thing)</pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>thing</code></dt> - <dd>Anything to be converted to a string.</dd> -</dl> - -<h3 id="Template_literals">Template literals</h3> - -<p>Starting with ECMAScript 2015, string literals can also be so-called <a href="/en-US/docs/Web/JavaScript/Reference/Template_literals">Template literals</a>:</p> - -<pre class="syntaxbox">`hello world` -`hello! - world!` -`hello ${who}` -escape `<a>${who}</a>`</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>nuova linea</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> - -<div class="note"> -<p>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> -</div> - -<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="Descrizione">Descrizione</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")}}, {{jsxref("undefined")}}, and for {{jsxref("Symbol", "symbols")}}. 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>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("40")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</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> - <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/it/web/javascript/reference/global_objects/string/indexof/index.html b/files/it/web/javascript/reference/global_objects/string/indexof/index.html deleted file mode 100644 index e8653cac62..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/indexof/index.html +++ /dev/null @@ -1,151 +0,0 @@ ---- -title: String.prototype.indexOf() -slug: Web/JavaScript/Reference/Global_Objects/String/indexOf -translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf ---- -<div>{{JSRef}}</div> - -<p>Il metodo <strong><code>indexOf()</code></strong> restituisce l'indice all'interno dell'oggetto {{jsxref("String")}} chiamante della prima occorrenza del valore specificato, avviando la ricerca su <code>fromIndex</code>. Restituisce -1 se il valore non viene trovato.</p> - -<div>{{EmbedInteractiveExample("pages/js/string-indexof.html")}}</div> - - - -<div class="note"><strong>Note:</strong> Per il metodo dell'Array, vedere {{jsxref("Array.prototype.indexOf()")}}.</div> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><var>str</var>.indexOf(<var>searchValue</var>[, <var>fromIndex</var>])</pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><var>searchValue</var></dt> - <dd>Una stringa che rappresenta il valore da cercare. Se non viene fornita esplicitamente alcuna stringa, <a href="https://tc39.github.io/ecma262/#sec-tostring"><var>searchValue</var> sarà forzato a <code>"undefined"</code></a> e questo valore verrà cercato nella stringa corrente.</dd> - <dt><var>fromIndex</var> {{optional_inline}}</dt> - <dd>Un numero intero che rappresenta l'indice al quale avviare la ricerca; il valore predefinito è <code>0</code>. Per valori <code>fromIndex</code> values inferiori a <code>0</code> o maggiori di <code>str.length</code>, la ricerca inizia rispettivamente con <code>0</code> e <code>str.length</code>.</dd> -</dl> - -<h3 id="Valore_di_ritorno">Valore di ritorno</h3> - -<p>L'indice della prima occorrenza di <em>searchValue</em> o <strong>-1</strong> se non trovato.<br> - Una stringa vuota <em>searchValue</em> corrisponderà a qualsiasi indice tra <code>0</code> e <code>str.length</code>.</p> - -<h2 id="Descrizione">Descrizione</h2> - -<p>I caratteri in una stringa sono indicizzati da sinistra a destra. L'indice del primo carattere è 0 e l'indice dell'ultimo carattere di una stringa chiamata <code>stringName</code> è <code>stringName.length - 1</code>.</p> - -<pre class="brush: js">'Blue Whale'.indexOf('Blue'); // ritorna 0 -'Blue Whale'.indexOf('Blute'); // ritorna -1 -'Blue Whale'.indexOf('Whale', 0); // ritorna 5 -'Blue Whale'.indexOf('Whale', 5); // ritorna 5 -'Blue Whale'.indexOf('Whale', 7); // ritorna -1 -'Blue Whale'.indexOf(''); // ritorna 0 -'Blue Whale'.indexOf('', 9); // ritorna 9 -'Blue Whale'.indexOf('', 10); // ritorna 10 -'Blue Whale'.indexOf('', 11); // ritorna 10 -</pre> - -<p>Il metodo <code>indexOf()</code> è case sensitive. Ad esempio, la seguente espressione restituisce -1:</p> - -<pre class="brush: js">'Blue Whale'.indexOf('blue'); // ritorna -1 -</pre> - -<h3 id="Controllo_delle_occorrenze">Controllo delle occorrenze</h3> - -<p>Nota che '0' non valuta <code>true</code> e '-1' non valuta <code>false</code>. Pertanto, quando si verifica se esiste una stringa specifica all'interno di un'altra stringa, il modo corretto per verificare sarebbe:</p> - -<pre class="brush: js">'Blue Whale'.indexOf('Blue') !== -1; // true -'Blue Whale'.indexOf('Bloe') !== -1; // false -</pre> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Usare_indexOf()">Usare <code>indexOf()</code></h3> - -<p>Nell'esempio seguente viene utilizzato <code>indexOf()</code> per individuare i valori nella stringa <code>"Brave new world"</code>.</p> - -<pre class="brush: js">const str = 'Brave new world'; - -console.log('L'indice della prima w dall'inizio è ' + str.indexOf('w')); // logga 8 -console.log('L'indice di "new" dall'inizio è ' + str.indexOf('new')); // logga 6 -</pre> - -<h3 id="indexOf()_e_il_case-sensitivity"><code>indexOf()</code> e il case-sensitivity</h3> - -<p>L'esempio seguente definisce due variabili stringa. Le variabili contengono la stessa stringa tranne che la seconda stringa contiene lettere maiuscole. Il primo metodo {{domxref("console.log()")}} mostra 19. Ma poiché il metodo <code>indexOf()</code> è case sensitive, la stringa <code>"cheddar"</code> non si trova in <code>myCapString</code>, quindi il secondo metodo <code>console.log()</code> mostra -1.</p> - -<pre class="brush: js">const myString = 'brie, pepper jack, cheddar'; -const myCapString = 'Brie, Pepper Jack, Cheddar'; - -console.log('myString.indexOf("cheddar") è ' + myString.indexOf('cheddar')); -// logs 19 -console.log('myCapString.indexOf("cheddar") è ' + myCapString.indexOf('cheddar')); -// logs -1 -</pre> - -<h3 id="Uso_di_indexOf()_per_contare_le_occorrenze_di_una_lettera_in_una_stringa">Uso di <code>indexOf()</code> per contare le occorrenze di una lettera in una stringa</h3> - -<p>L'esempio seguente imposta <code>count</code> sul numero di occorrenze della lettera <code>e</code> nella stringa <code>str</code>:</p> - -<pre class="brush: js">const str = 'Essere o non essere, questa è la domanda.'; -let count = 0; -let position = str.indexOf('e'); - -while (position !== -1) { - count++; - position = str.indexOf('e', position + 1); -} - -console.log(count); // mostra 4 -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Definizione iniziale.</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="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - - - -<p>{{Compat("javascript.builtins.String.indexOf")}}</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("String.prototype.charAt()")}}</li> - <li>{{jsxref("String.prototype.lastIndexOf()")}}</li> - <li>{{jsxref("String.prototype.includes()")}}</li> - <li>{{jsxref("String.prototype.split()")}}</li> - <li>{{jsxref("Array.prototype.indexOf()")}}</li> -</ul> diff --git a/files/it/web/javascript/reference/global_objects/string/length/index.html b/files/it/web/javascript/reference/global_objects/string/length/index.html deleted file mode 100644 index e575b777b8..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/length/index.html +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: string.length -slug: Web/JavaScript/Reference/Global_Objects/String/length -translation_of: Web/JavaScript/Reference/Global_Objects/String/length ---- -<div>{{JSRef}}</div> - -<p>La proprietà <strong><code>length</code></strong> di un oggetto {{jsxref("String")}} indica la lunghezza di una stringa, in unità di codice UTF-16<span class="seoSummary">.</span></p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code><var>str</var>.length</code></pre> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Questa proprietà restituisce il numero di unità di codice nella stringa. {{interwiki("wikipedia", "UTF-16")}}, il formato di stringa utilizzato da JavaScript, utilizza una singola unità di codice a 16 bit per rappresentare i caratteri più comuni, ma deve utilizzare due unità di codice per meno comunemente- caratteri usati, quindi è possibile che il valore restituito dalla <code>length</code> “lunghezza“ non corrisponda al numero effettivo di caratteri nella stringa.</p> - -<p>ECMASCript 2016 (ed. 7) ha stabilito una lunghezza massima di <code>2^53 - 1</code> elementi. In precedenza, non è stata specificata una lunghezza massima.. </p> - -<p>Per una stringa vuota, <code>length</code> è 0.</p> - -<p>La proprietà statica <code>String.length</code> restituisce il valore 1.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Basic_usage">Basic usage</h3> - -<pre class="brush: js">var x = 'Mozilla'; -var empty = ''; - -console.log('Mozilla is ' + x.length + ' code units long'); -/* "Mozilla è lungo 7 unità di codice" */ - -console.log('La stringa vuota ha una lunghezza di - ' + empty.length); -/* "La stringa vuota ha una lunghezza di 0" */</pre> - -<h3 id="Assegnazione_a_length">Assegnazione a length</h3> - -<pre class="brush: js">var myString = "bluebells"; - -// Il tentativo di assegnare un valore alla proprietà .length di una stringa non ha alcun effetto osservabile. -myString.length = 4; -console.log(myString); -/* "bluebells" */ -</pre> - -<h2 id="Specificazioni">Specificazioni</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificazioni</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Definizione iniziale Implementato in JavaScript 1.0.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.5.5.1', 'String.prototype.length')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibili">Browser compatibili</h2> - -<p class="hidden">La tabella di compatibilità in questa pagina è generata da dati strutturati. Se desideri contribuire ai dati, consulta <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> e inviaci una richiesta di pull</p> - -<p>{{Compat("javascript.builtins.String.length")}}</p> - -<h2 id="Guarda_anche">Guarda anche</h2> - -<ul> - <li><a href="http://developer.teradata.com/blog/jasonstrimpel/2011/11/javascript-string-length-and-internationalizing-web-applications">JavaScript <code>String.length</code> and Internationalizing Web Applications</a></li> -</ul> diff --git a/files/it/web/javascript/reference/global_objects/string/raw/index.html b/files/it/web/javascript/reference/global_objects/string/raw/index.html deleted file mode 100644 index 2d070b15cb..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/raw/index.html +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: String.raw() -slug: Web/JavaScript/Reference/Global_Objects/String/raw -translation_of: Web/JavaScript/Reference/Global_Objects/String/raw ---- -<div>{{JSRef}}</div> - -<p>Il metodo statico <strong><code>String.raw()</code></strong> è una funzione di tag del modello <a href="/en-US/docs/Web/JavaScript/Reference/template_strings">template string</a>, simile al prefisso <code>r</code> in Python o al prefisso <code>@</code> in C# per i valori letterali stringa (tuttavia c'è una differenza: vedere le spiegazioni in <a href="https://bugs.chromium.org/p/v8/issues/detail?id=5016" rel="noopener">questo numero</a> ). È usato per ottenere la stringa di stringhe di template non formattata, cioè le sostituzioni (ad esempio <font face="consolas, Liberation Mono, courier, monospace">${foo}</font>) vengono elaborate, ma gli escape (ad esempio <code>\n</code> ) non lo sono.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox"><code>String.raw(<var>callSite</var>, <var>...substitutions</var>) -String.raw`templateString` -</code></pre> - -<h3 id="Parametri">Parametri</h3> - -<dl> - <dt><code>callSite</code></dt> - <dd>Oggetto del sito di chiamata template ben formato, come <code>{ raw: ['foo', 'bar', 'baz'] }</code>.</dd> - <dt><code>...substitutions</code></dt> - <dd>Contiene valori di sostituzione.</dd> - <dt><code>templateString</code></dt> - <dd>A <a href="/en-US/docs/Web/JavaScript/Reference/template_strings">template string</a>, puoi sostituirlo opzionalmente (<code>${...}</code>).</dd> -</dl> - -<h3 id="Valore_resituto">Valore resituto</h3> - -<p>Restituisce una stringa non elaborata di un determinato Template String.</p> - -<h3 id="Eccezioni">Eccezioni</h3> - -<dl> - <dt>{{jsxref("TypeError")}}</dt> - <dd>Un oggetto {{jsxref("TypeError")}} viene generato se il primo argomento non è un oggetto formato.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Nella maggior parte dei casi, <code>String.raw()</code> viene utilizzato con template strings. La prima sintassi menzionata sopra è usata solo di rado, perché il motore JavaScript la chiamerà con argomenti appropriati, proprio come con altre <a href="/en-US/docs/Web/JavaScript/Reference/template_strings#Tagged_template_literals">funzioni tag</a> .</p> - -<p><code>String.raw()</code> è l'unica funzione di built-in tag incorporata nei template strings; funziona proprio come la funzione predefinita del modello ed esegue la concatenazione. Puoi anche ri-implementarlo con il normale codice JavaScript.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Utilizzo_di_String.raw()">Utilizzo di <code>String.raw()</code></h3> - -<pre class="brush: js">String.raw`Ciao\n${2+3}!`; -// 'Ciao\n5!', Il carattere dopo 'Ciao' non è un carattere di nuova riga, -// '\' e 'n' sono due caratteri. - -String.raw`Hi\u000A!`; -// 'Ciao\u000A!', Lo stesso qui, questa volta avremo il -// \, u, 0, 0, 0, A, 6 caratteri. -// Tutti i tipi di caratteri di escape saranno inefficaci -// e backslash saranno presenti nella stringa di output -// Puoi confermare questo controllando la proprietà .length -// della stringa. - -<code>let</code> name = 'Bob'; -String.raw`Ciao\n${name}!`; -// 'Ciao\nBob!', le sostituzioni vengono elaborate. - -// Normalmente non si chiama String.raw() come una funzione, -// ma la si chiama per simulare <code>`t${0}e${1}s${2}t` </code>puoi fare: -<code>String.raw({ raw: 'test' }, 0, 1, 2); // 't0e1s2t'</code> -// Nota che la stringa 'test', è un oggetto simile ad un array -// Il seguente è equivalente a -<code>// `foo${2 + 3}bar${'Java' + 'Script'}baz` -String.raw({ - raw: ['foo', 'bar', 'baz'] -}, 2 + 3, 'Java' + 'Script'); // 'foo5barJavaScriptbaz'</code></pre> - -<h2 id="Specificazioni">Specificazioni</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specificazioni</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-string.raw', 'String.raw')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Definizione iniziale.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.raw', 'String.raw')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_il_browser">Compatibilità con il browser</h2> - -<p class="hidden">La tabella di compatibilità in questa pagina è generata da dati strutturati. Se desideri contribuire ai dati, consulta <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> e inviaci una richiesta di pull.</p> - -<p>{{Compat("javascript.builtins.String.raw")}}</p> - -<h2 id="Guarda_anche">Guarda anche</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/template_strings">Template strings</a></li> - <li>{{jsxref("String")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar">Lexical grammar</a></li> -</ul> |