javascript-tutorial / javascript-tutorial/en.javascript.info

Documentation improvement: clarify function assignment behavior

Offen Anfängerfreundlich
#3,973 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
HTML
Sterne
25.5k
Forks
4k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I was reading the Function expressions section and noticed a wording choice that confused me a little.

The section mentions that we can "copy a function to another variable". Maybe the intention is to show that functions are values in JavaScript, the wording initially made me think that a new function was being created.

issue in the section -> url -> https://javascript.info/function-expressions
topic is "Function is a Value"

the example code was ->
function sayHi() { // (1) create
alert( "Hello" );
}

let func = sayHi; // (2) copy

func(); // Hello // (3) run the copy (it works)!
sayHi(); // Hello // this still works too (why wouldn't it)

My understanding is that func receives a reference to the same function object rather than creating an independent copy of the function itself.
There maybe a chance that i have misunderstood it , the copy could mean the reference is copied and a little context about reference would help even if it is included in the previous section.

This is not a major issue, but I thought a small clarification might help readers who are learning about values and references.

Thank you so much for the documentation

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Öffne den Abschnitt Function expressions unter https://javascript.info/function-expressions und suche das Thema „Function is a Value“ sowie dessen Zuweisungsbeispiel. Überprüfe die Formulierung rund um „copy a function“ und stelle klar, dass die Referenz auf dasselbe Funktionsobjekt zugewiesen wird, wobei das Verhalten des Beispiels erhalten bleibt. Als erledigt gilt die Aufgabe, wenn die Erklärung für Lernende eindeutig ist und das Beispiel weiterhin korrekt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.