dedlfix: in JavaScript einen String mit Zeilenumbruch notieren

Beitrag lesen

Hi!

Vermutlich macht sie das, aber sie ist in der ECMAScript-Spezifikation als unzulässig beschrieben. http://www.ecma-international.org/publications/standards/Ecma-262.htm - Seite 13 kurz vor Kapitel 7.
?? Was genau meinst du da?

"... if the Unicode escape sequence \u000A occurs within a string literal in a Java program, it is likewise interpreted as a line terminator, which is not allowed within a string literal—one must write \n instead of \u000A to cause a line feed to be part of the string value of a string literal."

Aber das ist wohl doch nicht das, was ich wollte, weil es sich auf Java bezieht.

Als ich den Kontextwechsel-Artikel schrieb, machte mich molily auf das Thema aufmerksam. Leider hatte ich damals keine Quellenangabe hinzugefügt sondern nur meine Interpretation in den Artikel geschrieben.

Ich denke, du meinst entweder eine andere Stelle oder du interpretierst diese Stelle falsch.

Es kommt noch eine Stelle bei den String-Literalen im Kapitel 7.8.4 auf Seite 24 (34. Seite des PDF-Dokuments).

"NOTE A line terminator character cannot appear in a string literal, except as part of a LineContinuation to produce the empty character sequence. The correct way to cause a line terminator character to be part of the String value of a string literal is to use an escape sequence such as \n or \u000A."

Auseinandergenommen:

A line terminator character cannot appear in a string literal,

das Problem des OPs

except as part of a LineContinuation to produce the empty character sequence.

LineContinuation ist definiert als Backslash plus (CR)LF (und noch ein paar mehr Möglichkeiten) und erzeugt nur einen Leerstring.

The correct way to cause a line terminator character to be part of the String value of a string literal is to use an escape sequence such as \n or \u000A.

Nur \n und \u000A können zum Einfügen eines Zeilenumbruchs verwendet werden.

Also update ich mein Wissen nun, dass zwar \ vor einem Zeilenumbruch erlaubt ist, aber nur einen Zeilenumbruch im Code erzeugt, nicht jedoch im String selbst.

Danke fürs Intervenieren.

Lo!