From 4b1a9203c547c019fc5398082ae19a3f3d4c3efe Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:15 -0500 Subject: initial commit --- .../fehler/strict_non_simple_params/index.html | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 files/de/web/javascript/reference/fehler/strict_non_simple_params/index.html (limited to 'files/de/web/javascript/reference/fehler/strict_non_simple_params') diff --git a/files/de/web/javascript/reference/fehler/strict_non_simple_params/index.html b/files/de/web/javascript/reference/fehler/strict_non_simple_params/index.html new file mode 100644 index 0000000000..a288a81a10 --- /dev/null +++ b/files/de/web/javascript/reference/fehler/strict_non_simple_params/index.html @@ -0,0 +1,111 @@ +--- +title: 'SyntaxError: "use strict" not allowed in function with non-simple parameters' +slug: Web/JavaScript/Reference/Fehler/Strict_Non_Simple_Params +tags: + - Errors + - JavaScript + - TypeError +translation_of: Web/JavaScript/Reference/Errors/Strict_Non_Simple_Params +--- +
{{jsSidebar("Errors")}}
+ +

Fehlermeldung

+ +
Firefox:
+SyntaxError: "use strict" not allowed in function with default parameter
+SyntaxError: "use strict" not allowed in function with rest parameter
+SyntaxError: "use strict" not allowed in function with destructuring parameter
+
+Chrome:
+SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
+
+ +

Fehlertyp

+ +

{{jsxref("SyntaxError")}}.

+ +

Was ist falsch gelaufen?

+ +

Eine "use strict" Direktive steht am Anfang einer Funktion, die einen der folgende Parameter hat:

+ + + +

Eine "use strict" Direktive ist am Anfang solcher Funktionen durch die ECMAScript Spezifikation nicht erlaubt.

+ +

Beispiele

+ +

Funktionsstatement

+ +

In diesem Fall hat die Funktion sum zwei Standardparameter a=1 und b=2:

+ +
function sum(a = 1, b = 2) {
+  // SyntaxError: "use strict" not allowed in function with default parameter
+  'use strict';
+  return a + b;
+}
+
+ +

Wenn die Funktion im Strict Mode sein soll und das Skript oder die umschließende FUnktion auch für den Strict Mode in Ordnung ist, kann man die "use strict" Direktive nach außen verschieben:

+ +
'use strict';
+function sum(a = 1, b = 2) {
+  return a + b;
+}
+
+ +

Funktionsausdruck

+ +

Bei eine Funktionsausdruck kann ein andere Workaround genutzt werden:

+ +
var sum = function sum([a, b]) {
+  // SyntaxError: "use strict" not allowed in function with destructuring parameter
+  'use strict';
+  return a + b;
+};
+
+ +

Dieses kann zu folgendem Ausdruck konvertiert werden:

+ +
var sum = (function() {
+  'use strict';
+  return function sum([a, b]) {
+    return a + b;
+  };
+})();
+
+ +

Pfeilfunktionen

+ +

Wenn eine Pfeilfunktion auf die this Variable zugreift, so kann eine umschließende Pfeilfunktion benutzt werden:

+ +
var callback = (...args) => {
+  // SyntaxError: "use strict" not allowed in function with rest parameter
+  'use strict';
+  return this.run(args);
+};
+
+ +

Dieses kann zu folgendem Ausdruck konvertiert werden:

+ +
var callback = (() => {
+  'use strict';
+  return (...args) => {
+    return this.run(args);
+  };
+})();
+
+ +

Siehe auch

+ + -- cgit v1.2.3-54-g00ecf