Sto leggendo il libro "Javascript: Le parti buone".
Ora mi sto leggendo il capitolo su Tipi Convertire i:TypeError: this.prototype non è definito quando si chiama Function.prototype.method()
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
UPDATE:
Perché seguente codice non funziona?
js> Function.prototype.method("test", function(){print("TEST")});
typein:2: TypeError: this.prototype is undefined
Ma seguente codice funziona senza problemi:
js> Function.method("test", function(){print("TEST")});
function Function() {[native code]}
Perché questo codice funziona?
js> var obj = {"status" : "ST"};
js> typeof obj;
"object"
js> obj.method = function(){print(this.status)};
(function() {print(this.status);})
js> obj.method();
ST
"obj" è un oggetto.
Ma posso chiamare il metodo "metodo" su di esso.
Qual è la differenza tra Function.prototype.method e obj.method?
Grazie. Ora capisco. Non ho prestato attenzione alla seguente riga this.prototype [nome] = func; –