Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/06/2014, 05:49
Avatar de marlanga
marlanga
 
Fecha de Ingreso: enero-2011
Ubicación: Murcia
Mensajes: 1.024
Antigüedad: 13 años, 3 meses
Puntos: 206
Respuesta: Comportamiento extraño: Require.js y herencia javascript

Código Javascript:
Ver original
  1. OutputX.prototype = NodeX.prototype;
  2. TableX.prototype = NodeX.prototype;
Esto no sirve para heredar. Estás igualando prototipos, has hecho que los tres "objetos" tengan el mismo prototipado. El comportamiento es raro, pero es fácil de evitar.

Cambialos por la mejor forma de heredar que he visto de momento:
Código Javascript:
Ver original
  1. OutputX.prototype = Object.create(NodeX.prototype);
  2. TableX.prototype = Object.create(NodeX.prototype);

Ejemplo completo:
Código Javascript:
Ver original
  1. function NodeX(){};
  2. NodeX.prototype.bla = function(){
  3.     console.log("NodeX.prototype.bla");
  4. }
  5.  
  6. function OutputX(){}
  7.  
  8. OutputX.prototype = Object.create(NodeX.prototype);
  9.  
  10. OutputX.prototype.foo = function(){
  11.     console.log("OutputX.prototype.foo");
  12. }
  13.  
  14. function TableX(){};
  15.  
  16. TableX.prototype = Object.create(NodeX.prototype);
  17.  
  18. TableX.prototype.foo = function(){
  19.     console.log("TableX.prototype.foo");
  20. }
  21. TableX.prototype.bar = function(){
  22.     console.log("TableX.prototype.bar");
  23. }
  24.  
  25. var o = new OutputX;
  26. o.foo();
  27. o.bla();
  28. o.bar();