pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Errors/Strict_non_simple_params

b4c5a1e2a5.js" type="module">

Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

SyntaxError: "use strict" nicht erlaubt in Funktion mit nicht einfachen Parametern

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.

Meldung

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)

Fehlertyp

SyntaxError.

Was ist schiefgelaufen?

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.

Beispiele

Funktionsdeklaration

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

js
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, können Sie die "use strict"-Anweisung außerhalb der Funktion verschieben:

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

Funktionsausdruck

Ein Funktionsausdruck kann eine andere Lösung verwenden:

js
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:

js
const sum = (function () {
  "use strict";
  return function sum([a, b]) {
    return a + b;
  };
})();

Pfeilfunktion

Wenn eine Pfeilfunktion auf die Variable this zugreifen muss, können Sie die Pfeilfunktion als umgebende Funktion verwenden:

js
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:

js
const callback = (() => {
  "use strict";
  return (...args) => this.run(args);
})();

Siehe auch

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy