aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/global_objects/string/raw/index.html
blob: 4405b1b72dcec034c68162e2b76e0ff27467f2fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: String.raw()
slug: Web/JavaScript/Reference/Global_Objects/String/raw
tags:
  - ECMAScript 2015
  - JavaScript
  - Method
  - Reference
  - String
translation_of: Web/JavaScript/Reference/Global_Objects/String/raw
---
<div>{{JSRef}}</div>

<div>Die statische <strong><code>String.raw()</code></strong> Methode ist eine tag Funktion für <a href="/de/docs/Web/JavaScript/Reference/template_strings">template literale</a> ähnlich dem r Präfix in Python oder dem @ Präfix in C# für String Literale (es gibt jedoch einen Unterschied: siehe in der Beschreibung <a href="https://bugs.chromium.org/p/v8/issues/detail?id=5016">dieses Issues</a>). Es wird verwendet um rohen, unveränderten Text zu verwenden.</div>

<div> </div>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><code>String.raw(<var>callSite</var>, <var>...substitutions</var>)
String.raw`templateString`
</code></pre>

<h3 id="Parameter">Parameter</h3>

<dl>
 <dt><code>callSite</code></dt>
 <dd>Sauber formatiertes template call object, wie <code>{ raw: 'string' }</code>.</dd>
 <dt><code>...substitutions</code></dt>
 <dd>Enthält Substitutionswerte.</dd>
 <dt><code>templateString</code></dt>
 <dd>Ein <a href="/de/docs/Web/JavaScript/Reference/template_strings">template string</a>, optional mit Substitutionen (<code>${...}</code>).</dd>
</dl>

<h3 id="Rückgabewerte">Rückgabewerte</h3>

<p>Einen rohen, unveränderbaren String des template Strings.</p>

<h3 id="Auftretende_Errors">Auftretende Errors</h3>

<dl>
 <dt>{{jsxref("TypeError")}}</dt>
 <dd>Ein {{jsxref("TypeError")}}  wird ausgeworfen wenn das erste Argument nicht sauber formatiert ist.</dd>
</dl>

<h2 id="Beschreibung">Beschreibung</h2>

<p>Meistens wird <code>String.raw()</code> mit template strings (Vorlagen-Zeichenketten) benutzt. Die erste oben beschriebene Syntax wird kaum benutzt weil die JavaScript engine die Argumente richtig aufrufen wird so wie bei anderen <a href="/de/docs/Web/JavaScript/Reference/template_strings#Tagged_template_strings">tag Funktionen.</a></p>

<p><code>String.raw()</code> ist die einzige built-in tag function für template strings; Sie funktioniert wie eine default template function und führt concatenation (Verbindung mehrerer Strings zu einem) aus. Man kann sie sogar mit JS code neu schreiben.</p>

<h2 id="Beispiele">Beispiele</h2>

<h3 id="Verwendung_von_String.raw()">Verwendung von <code>String.raw()</code></h3>

<pre class="brush: js">String.raw`Hi\n${2+3}!`;
// 'Hi\\n5!', das Zeichen nach 'Hi' ist kein newline (Zeilenumbruch) Zeichen,
// '\' und 'n' sind zwei Zeichen.

String.raw`Hi\u000A!`;
// 'Hi\\u000A!', hier genauso, diesmal bekommen wir folgende Zeichen zurrück:
//  \, u, 0, 0, 0, A, 6
// Alle Typen von escape characters (besondere Steuerzeichen) sind ineffektiv
// Backslashes werden unverändert ausgegeben.
// Man kann dies prüfen indem man die .length property des strings abfragt
console.log( String.raw`Hi\u000A!`.length ) // gibt 9 zurrück
console.log( "Hi\u000A!".length ) // gibt 4 zurrück


let name = 'Bob';
String.raw`Hi\n${name}!`;
// 'Hi\\nBob!', Substitutionen werden bearbeitet.

// Normalerweise ruft man  String.raw() nicht als function auf aber man kann
//folgendes:
String.raw({ raw: 'test' }, 0, 1, 2);
// 't0e1s2t'
</pre>

<h2 id="Spezifikationen">Spezifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Spezifikation</th>
   <th scope="col">Status</th>
   <th scope="col">Kommentar</th>
  </tr>
  <tr>
   <td>{{SpecName('ES2015', '#sec-string.raw', 'String.raw')}}</td>
   <td>{{Spec2('ES2015')}}</td>
   <td>Initiale Definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-string.raw', 'String.raw')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browserkompatibilität">Browserkompatibilität</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>41</td>
   <td>{{CompatGeckoDesktop("34")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>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>41</td>
   <td>{{CompatGeckoMobile("34")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/de/docs/Web/JavaScript/Reference/template_strings">Template strings</a></li>
 <li>{{jsxref("String")}}</li>
 <li><a href="/de/docs/Web/JavaScript/Reference/Lexical_grammar">Lexical grammar</a></li>
</ul>