Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the main issue is in the prototype of Gentlemen. For one you are overwriting the prototype youve inherited from Human, for another you are using = instead of : to assign the functions :)</p> <p>Try this:</p> <pre><code> var People = People || {}; People = (function() { var _people = []; var People = function(){}; var addGentleman = function (name) { _people.push(new People.Gentleman(name)); }; var getList = function () { var temp = []; for (var i = 0; i &lt; _people.length; i++) { temp.push(_people[i].toString()); } return temp; }; People.prototype = { constructor: People, addGentleman: addGentleman, getList: getList }; return People; })(); People.Human = (function () { this._name; var Human = function (name) { this._name = name; }; Human.prototype = { constructor: Human, }; return Human; })(); People.Gentleman = (function () { var Gentleman = function (name) { People.Human.call(this, name); } var toString = function () { return 'Mr. ' + this._name; }; Gentleman.prototype = Object.create(People.Human.prototype); Gentleman.prototype.constructor = Gentleman; Gentleman.prototype.toString = toString; return Gentleman; })(); $(function () { var people = new People(); people.addGentleman('Viktor'); // this is me people.addGentleman('Joakim'); // and my friend! var list = people.getList(); var $ul = $('#people'); for (var i = 0; i &lt; list.length; i++) { $ul.append('&lt;li&gt;' + list[i] + '&lt;/li&gt;'); } }); </code></pre> <p>You can see that I have added the new toString method to the prototype object rather than overwriting whats already there. I dont know if the pattern has a nicer way to do this (im not familiar with it).</p> <p>You could do this if it seems more appropriate:</p> <pre><code>Gentleman.prototype = Object.create(People.Human.prototype, { constructor : { configurable: true, get : function() { return Gentleman } }, toString : { configurable: true, get : function() { return toString } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload