| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Errors/Strict_non_simple_params | [Back] [Original] |
Get to know MDN better
Dieser Inhalt wurde automatisch aus dem Englischen bersetzt, und kann Fehler enthalten. Erfahre mehr ber dieses Experiment.
Der JavaScript-Fehler ""use strict" nicht erlaubt in Funktion" tritt auf,
wenn eine "use strict"-Anweisung am Anfang einer Funktion verwendet wird, die
Standardparameter,
Rest-Parameter oder
Destrukturierungs-Parameter hat.
SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list (V8-based) SyntaxError: "use strict" not allowed in function with default parameter (Firefox) SyntaxError: "use strict" not allowed in function with rest parameter (Firefox) SyntaxError: "use strict" not allowed in function with destructuring parameter (Firefox) SyntaxError: 'use strict' directive not allowed inside a function with a non-simple parameter list. (Safari)
Eine "use strict"-Anweisung ist am Anfang einer Funktion geschrieben, die einen
der folgenden Parameter hat:
Eine "use strict"-Anweisung ist am Anfang solcher Funktionen laut
der ECMAScript-Spezifikation nicht erlaubt.
In diesem Fall hat die Funktion sum 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 gesamte Skript oder die umgebende Funktion ebenfalls im Strict Mode sein kann, knnen Sie die
"use strict"-Anweisung auerhalb der Funktion verschieben:
"use strict";
function sum(a = 1, b = 2) {
return a + b;
}
Ein Funktionsausdruck kann eine andere Lsung verwenden:
const sum = function sum([a, b]) {
// SyntaxError: "use strict" not allowed in function with destructuring parameter
"use strict";
return a + b;
};
Dies kann in den folgenden Ausdruck umgewandelt werden:
const sum = (function () {
"use strict";
return function sum([a, b]) {
return a + b;
};
})();
Wenn eine Pfeilfunktion auf die Variable this zugreifen muss, knnen Sie die
Pfeilfunktion als umgebende Funktion verwenden:
const callback = (...args) => {
// SyntaxError: "use strict" not allowed in function with rest parameter
"use strict";
return this.run(args);
};
Dies kann in den folgenden Ausdruck umgewandelt werden:
const callback = (() => {
"use strict";
return (...args) => this.run(args);
})();
Der Bauplan fr ein besseres Internet.
Teile dieses Inhalts sind 19982026 von einzelnen mozilla.org-Mitwirkenden. Inhalte sind verfgbar unter einer Creative-Commons-Lizenz.
| Web Proxy Viewer | New URL | Original Page |