JavaScript-Instanzfunktionen versus Prototypfunktionen [duplizieren]

Mögliche Duplikate:
Verwendung von 'prototype' vs. 'this' in Javascript?

Ich verstehe die verschiedenen Arten von JavaScript-Funktionen wie folgt:

function MyObj() {
    this.propOne = true;
    this.publicInstanceFunc = function() {
        if (propOne)
            return 'public instance function';
    }
    function privateFunc() {
        return 'private function only visible inside this constructor';
    }
}

MyObj.prototype.protoFunc = function() {
    if (this.propOne)
        return 'prototype function shared amongst all instances of MyObj';
}
Sind diese richtig?In welchen Fällen sollte man dem Prototyp Funktionen zuweisen (z.protoFunc) im Vergleich zum Konstruktor (z.publicInstanceFunc)?Benutztthis die richtige Art, auf Eigenschaften innerhalb von Prototypfunktionen zuzugreifen?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage