Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Establish Inheritance Between Objects in JavaScript?
    primarykey
    data
    text
    <p>I have the following code that creates two objects (ProfileManager and EmployerManager) where the object EmployerManager is supposed to inherit from the object ProfileManager. However, when I do alert(pm instanceof ProfileManager); it returns false.</p> <pre><code>function ProfileFactory(profileType) { switch(profileType) { case 'employer': return new EmployerManager(); break; } } function ProfileManager() { this.headerHTML = null; this.contentHTML = null; this.importantHTML = null; this.controller = null; this.actions = new Array(); this.anchors = new Array(); } ProfileManager.prototype.loadData = function(action, dao_id, toggleBack) { var step = this.actions.indexOf(action); var prv_div = $('div_' + step - 1); var nxt_div = $('div_' + step); new Ajax.Request(this.controller, { method: 'get', parameters: {action : this.actions[step], dao_id : dao_id}, onSuccess: function(data) { nxt_div.innerHTML = data.responseText; if(step != 1 &amp;&amp; !prv_div.empty()) { prv_div.SlideUp(); } nxt_div.SlideDown(); for(i = 1; i &lt;= step; i++) { if($('step_anchor_' + i).innerHTML.empty()) { $('step_anchor_' + i).innerHTML = this.anchors[i]; } } } } ) } EmployerManager.prototype.superclass = ProfileManager; function EmployerManager() { this.superclass(); this.controller = 'eprofile.php'; this.anchors[1] = 'Industries'; this.anchors[2] = 'Employer Profiles'; this.anchors[3] = 'Employer Profile'; this.actions[1] = 'index'; this.actions[2] = 'employer_list'; this.actions[3] = 'employer_display'; } var pm = new ProfileFactory('employer'); alert(pm instanceof ProfileManager); </code></pre> <p>BTW, this is my very first attempt at Object-Oriented JavaScript, so if you feel compelled to comment on the stupidity of my approach please feel free to do so, but offer suggestions on how to approach the problem better.</p>
    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.
 

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