-1
implementieren Wie kann ichWie Vorfunktion in JavaScript
callMethod(); // Works
callMethod.doThisWay(); // Still works
implementieren Wie kann ichWie Vorfunktion in JavaScript
callMethod(); // Works
callMethod.doThisWay(); // Still works
Sure Unterfunktionen in JavaScript implementieren können Sie :-)
Schreiben Sie einfach
const callMethod = function() {
// ...
};
callMethod.doThisWay = function() {
// ...
};
und fertig: -)
Das funktioniert auch:
var callMethod = function() {
this.doThisWay = function() {
alert('doThisWay');
}
alert('callMethod');
return this;
};
var a = new callMethod();
a.doThisWay();
gibt es auch andere Möglichkeiten, dies zu tun.
Nun, was hast du probiert? Da Funktionen Eigenschaften enthalten können, sollte der triviale Ansatz funktionieren. – doldt
Randnotiz: Eine Unterfunktion wird als "(statische) Methode" bezeichnet – Oisin