aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/string/raw
diff options
context:
space:
mode:
Diffstat (limited to 'files/es/web/javascript/reference/global_objects/string/raw')
-rw-r--r--files/es/web/javascript/reference/global_objects/string/raw/index.html113
1 files changed, 113 insertions, 0 deletions
diff --git a/files/es/web/javascript/reference/global_objects/string/raw/index.html b/files/es/web/javascript/reference/global_objects/string/raw/index.html
new file mode 100644
index 0000000000..fbdc195d5c
--- /dev/null
+++ b/files/es/web/javascript/reference/global_objects/string/raw/index.html
@@ -0,0 +1,113 @@
+---
+title: String.raw()
+slug: Web/JavaScript/Reference/Global_Objects/String/raw
+translation_of: Web/JavaScript/Reference/Global_Objects/String/raw
+original_slug: Web/JavaScript/Referencia/Objetos_globales/String/raw
+---
+<div>{{JSRef}}</div>
+
+<p>El método estatico <strong><code>String.raw()</code> </strong> es una función de <a href="/en-US/docs/Web/JavaScript/Reference/template_strings"> plantilla de literales</a>, similar al prefijo <code>r</code> en Python o al prefijo <code>@</code> en C# para strings literales (con ciertas diferencias: ver la explicación en <a href="https://bugs.chromium.org/p/v8/issues/detail?id=5016">este problema</a>). Se utiliza para obtener un <em>string</em> crudo a partir de plantillas de <em>string</em> (es decir, el original, texto no interpretado).</p>
+
+<h2 id="Sintaxis">Sintaxis</h2>
+
+<pre class="syntaxbox"><code>String.raw(<var>callSite</var>, <var>...substitutions</var>)
+
+String.raw`templateString`
+</code></pre>
+
+<h3 id="Parametros">Parametros</h3>
+
+<dl>
+ <dt><code>callSite</code></dt>
+ <dd>Plantilla bien estructurada, similar a <code>{ raw: ['foo', 'bar', 'baz'] }</code>.</dd>
+ <dt><code>...substitutions</code></dt>
+ <dd>Contiene valores de sustitución.</dd>
+ <dt><code>templateString</code></dt>
+ <dd>[opcional] Una <a href="/en-US/docs/Web/JavaScript/Reference/template_strings">plantilla <em>string</em></a>, con sustituciones (<code>${...}</code>).</dd>
+</dl>
+
+<h3 id="Valor_de_regreso">Valor de regreso</h3>
+
+<p>La forma cruda del <em>string </em>de una plantilla <em>string </em>proporcionada.</p>
+
+<h3 id="Excepciones">Excepciones</h3>
+
+<dl>
+ <dt>{{jsxref("TypeError")}}</dt>
+ <dd>Un {{jsxref("TypeError")}} es arrojado si el primer argumento no es un objeto bien estructurado.</dd>
+</dl>
+
+<h2 id="Descripción">Descripción</h2>
+
+<p>En la mayoría de los casos, <code>String.raw()</code> es usado con plantillas <em>string</em>. La primera sintaxis mencionada arriba es raramente usada,  porque el motor de JavaScript hará la llamada por ti con los argumentos apropiados, al igual que otras <a href="/en-US/docs/Web/JavaScript/Reference/template_strings#Tagged_template_literals">funciones de etiqueta</a>.</p>
+
+<p><code>String.raw()</code> es la unica función de etiqueta incorporada en las plantillas <em>string</em>; trabaja igual que la función de la plantilla por defecto y ejecuta la concatenación. Incluso puedes reimplementarlo con código normal de JavaScript.</p>
+
+<h2 id="Ejemplos">Ejemplos</h2>
+
+<h3 id="Usando_String.raw()">Usando <code>String.raw()</code></h3>
+
+<pre class="brush: js">String.raw`Hi\n${2+3}!`;
+// 'Hi\n5!', the character after 'Hi'
+// is not a newline character,
+// '\' and 'n' are two characters.
+
+String.raw`Hi\u000A!`;
+// 'Hi\u000A!', same here, this time we will get the
+// \, u, 0, 0, 0, A, 6 characters.
+// All kinds of escape characters will be ineffective
+// and backslashes will be present in the output string.
+// You can confirm this by checking the .length property
+// of the string.
+
+let name = 'Bob';
+String.raw`Hi\n${name}!`;
+// 'Hi\nBob!', substitutions are processed.
+
+// Normally you would not call String.raw() as a function,
+// but to simulate `t${0}e${1}s${2}t` you can do:
+String.raw({ raw: 'test' }, 0, 1, 2); // 't0e1s2t'
+// Note that 'test', a string, is an array-like object
+// The following is equivalent to
+// `foo${2 + 3}bar${'Java' + 'Script'}baz`
+String.raw({
+  raw: ['foo', 'bar', 'baz']
+}, 2 + 3, 'Java' + 'Script'); // 'foo5barJavaScriptbaz'
+
+</pre>
+
+<h2 id="Especificaciónes">Especificaciónes</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificación</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentario</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-string.raw', 'String.raw')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td>Definicion inicial.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.raw', 'String.raw')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidad_de_navegador">Compatibilidad de navegador</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.raw")}}</p>
+
+<h2 id="Tambien_ver">Tambien ver</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>