Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript inheritance
    primarykey
    data
    text
    <p>I'm trying a few different approaches to Javascript inheritance at the moment. I have the following code:</p> <p>('borrowed' from <a href="http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm" rel="nofollow noreferrer">http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm</a>)</p> <pre><code>KV = {}; KV.extend = function(subClass, baseClass) { function inheritance() {} inheritance.prototype = baseClass.prototype; subClass.prototype = new inheritance(); subClass.prototype.constructor = subClass; subClass.baseConstructor = baseClass; subClass.superClass = baseClass.prototype; } function GridView() { var _ownerElement; } GridView.prototype.getOwnerElement = function() { return this._ownerElement; } GridView.prototype.setOwnerElement = function(ownerElement) { this._ownerElement = ownerElement; } GridView.prototype.initialize = function() { this.setOwnerElement('test'); } function StreetGridView(dataURL, ownerElement) { StreetGridView.baseConstructor.call(this); StreetGridView.superClass.initialize(); StreetGridView.superClass.setOwnerElement(ownerElement); } // subclass StreetGridView KV.extend(StreetGridView, GridView); </code></pre> <p>Now, when I create an instance of StreetGridView, I can call getOwnerElement() on it no problem. Everything works as expected.</p> <p>HOWEVER</p> <p>When I create ANOTHER instance, any changes made to instance 2 are reflected back in instance 1.</p> <p>I know this is the main problem with using prototypes as the share instance information. I've been racking my brains this morning but wondered if there was someone out there who could point me in the right direction!</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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