alankis

Undefined error - JS inheritance

Oct 28th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Class(object) {
  2.     this.title = object.title;
  3.     this.getTitle = function() {
  4.         return this.title;
  5.         };
  6. };
  7.  
  8. var c1 = new Class({
  9.     title: 'This is class'
  10. });
  11.  
  12.  
  13.  
  14. c1.getTitle();
  15. // define here subclass
  16.  
  17. function SubClass(object) {
  18.     this.title = object.title;
  19. };
  20. SubClass.prototype = new Class();
  21. SubClass.prototype.constructor = SubClass;
  22.  
  23.  
  24. // TypeError: Cannot read property 'title' of undefined
Advertisement
Add Comment
Please, Sign In to add comment