ejecute el siguiente fragmento de código y ver lo que está sucediendo en JS consola:Cómo volver a definir un método en un "javascript clase"
Mis preguntas son con respecto a la última línea en el fragmento:
- ¿Por qué ha cambiado
F.prototype.method;
? - ¿Cómo debo redefinir
Fcustom.prototype.method
para no cambiarF.prototype.method
?
Nota: Estoy usando jQuery y guión bajo para extender la función.
Código de ensayo fragmento:
var F = function() {}; F.prototype.method = function() { // some code } F.prototype.method; // it shows "some code" Fcustom = $.extend(true, F, {}); _.extend(Fcustom.prototype, { method: function() { // other code } }); Fcustom.prototype.method; // it shows "other code" F.prototype.method; // it shows "other code" instead of "some code" Why?
¿Desea copiar la función 'F' a' Fcustom'? – pimvdb
Desafortunadamente no puedes clonar funciones ... –