-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function expressions #29
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @BitcoinElf vielen Dank für deinen Pull-Request.
Ich habe nur bis zur Zeile 43 eine Review durchgeführt, da irgendwo ab Zeile 40 die Formatierung des Originals verloren geht. Kannst du das bitte wieder anpassen, danach werden ich mir den Rest ansehen.
@@ -1,70 +1,67 @@ | |||
# Function expressions | |||
# Function Expressions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Function Expressions | |
# Funktionsausdruck |
|
||
The syntax that we used before is called a *Function Declaration*: | ||
Bisher haben wir die Syntax *Function Declaration* benutzt. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bisher haben wir die Syntax *Function Declaration* benutzt. | |
Die Syntax, die wir zuvor verwendet haben, wird *Funktionsdeklaration* genannt: |
|
||
```js | ||
function sayHi() { | ||
alert( "Hello" ); | ||
} | ||
``` | ||
|
||
There is another syntax for creating a function that is called a *Function Expression*. | ||
Es gibt allerdings auch die Syntax namens *Function Expression* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Es gibt allerdings auch die Syntax namens *Function Expression* | |
Es gibt eine weitere Syntax zum Erstellen einer Funktion, die als *Funktionsausdruck* bezeichnet wird. |
|
||
It looks like this: | ||
Diese sieht so aus: | ||
|
||
```js | ||
let sayHi = function() { | ||
alert( "Hello" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alert( "Hello" ); | |
alert( "Hallo" ); |
|
||
```js | ||
let sayHi = function() { | ||
alert( "Hello" ); | ||
}; | ||
``` | ||
|
||
Here, the function is created and assigned to the variable explicitly, like any other value. No matter how the function is defined, it's just a value stored in the variable `sayHi`. | ||
Hier wird die Funktion erstellt und einer Variable explizit zugewiesen, wie jeder andere Wert. Unabhängig davon, wie die Funktion definiert ist, ist sie nur ein Wert, den wir in der variable `sayHi` speichern. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hier wird die Funktion erstellt und einer Variable explizit zugewiesen, wie jeder andere Wert. Unabhängig davon, wie die Funktion definiert ist, ist sie nur ein Wert, den wir in der variable `sayHi` speichern. | |
Hier wird die Funktion erstellt und einer Variable explizit zugewiesen, wie jeder andere Wert. Unabhängig davon, wie die Funktion definiert ist, ist sie nur ein Wert, den wir in der Variable `sayHi` speichern. |
*/!* | ||
``` | ||
|
||
Please note that the last line does not run the function, because there are no parentheses after `sayHi`. There are programming languages where any mention of a function name causes its execution, but JavaScript is not like that. | ||
Interessanterweise führt die letzte Zeile die Funktion nicht aus, denn hinter `sayHi` befinden sich keine Klammern. In einigen Programmiersprachen führt jede Erwähnung einer Funktion zur Ausführung, JavaScript gehört nicht dazu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interessanterweise führt die letzte Zeile die Funktion nicht aus, denn hinter `sayHi` befinden sich keine Klammern. In einigen Programmiersprachen führt jede Erwähnung einer Funktion zur Ausführung, JavaScript gehört nicht dazu. | |
Bitte beachte, dass die letzte Zeile die Funktion nicht ausführt, da nach `sayHi` keine Klammern stehen. In einigen Programmiersprachen führt jede Erwähnung einer Funktion zur Ausführung, JavaScript gehört nicht dazu. |
|
||
In JavaScript, a function is a value, so we can deal with it as a value. The code above shows its string representation, which is the source code. | ||
In JavaScript ist eine Funktion ein Wert, also können wir damit auch umgehen, wie mit einem Wert. Der obige code zeigt die Funktion als String an, zeigt also den Quellcode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JavaScript ist eine Funktion ein Wert, also können wir damit auch umgehen, wie mit einem Wert. Der obige code zeigt die Funktion als String an, zeigt also den Quellcode. | |
In JavaScript ist eine Funktion ein Wert, so dass wir sie als Wert behandeln können. Der obige Code zeigt seine Zeichenkettendarstellung, die den Quellcode darstellt. |
|
||
```js run no-beautify | ||
function sayHi() { // (1) create | ||
function sayHi() { // (1) erstellen | ||
alert( "Hello" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alert( "Hello" ); | |
alert( "Hallo" ); |
|
||
func(); // Hello // (3) run the copy (it works)! | ||
sayHi(); // Hello // this still works too (why wouldn't it) | ||
func(); // Hello // (3) Kopie ausführen(klappt)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func(); // Hello // (3) Kopie ausführen(klappt)! | |
func(); // Hallo // (3) führe die Kopie aus (es funktioniert)! |
func(); // Hello // (3) run the copy (it works)! | ||
sayHi(); // Hello // this still works too (why wouldn't it) | ||
func(); // Hello // (3) Kopie ausführen(klappt)! | ||
sayHi(); // Hello // Die Funktion funktioniert immernoch (warum auch nicht?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sayHi(); // Hello // Die Funktion funktioniert immernoch (warum auch nicht?) | |
sayHi(); // Hallo // das funktioniert immer noch (warum sollte es nicht) |
Please make the requested changes. After it, add a comment "/done". |
German Translation of article Function Expressions