Note that there are some explanatory texts on larger screens.

plurals
  1. POInherit from 2 objects
    primarykey
    data
    text
    <p>I have a question about object inheritance with Object.create. </p> <p>I have two objects, that should behave like interfaces. <code>Object3D</code> and <code>Light</code>. <code>Object3D</code> presents real object in 3D space. It has its position in space and it should have some functions to for example change this position. <code>Light</code> is everything that glows. And every light has its color. </p> <pre><code>// I have resons to use iif, dont bother with that ;) var Object3D = (function() { var Object3D = function() { this.position = vec3.create(); }; return Object3D; })(); var Light = (function() { var Light = function() { this.color = new Array(4); }; return Light; })(); </code></pre> <p>Now, I want to have two another objects, which will be 'classes'. First one is <code>AmbientLight</code>. <code>AmbientLight</code> doesnt have position, because it just glows everywhere. So it inherits from <code>Light</code>. The other one is <code>PointLight</code>. <code>PointLight</code> is <code>Light</code>, but it has also position, because it doesn't glow everywhere. It has some range. So it should inherit also from <code>Object3D</code>. How can I do it? Can I merge results from Object.create? </p> <pre><code>var AmbientLight = (function() { var AmbientLight = function() { Light.call(this); }; AmbientLight.prototype = Object.create(Light.prototype); return AmbientLight; })(); var PointLight = (function() { var PointLight = function() { Light.call(this); Object3D.call(this); this.range = 10.0; }; // this isnt correct // how to make it correct? PointLight.prototype = Object.create(Light.prototype); PointLight.prototype = Object.create(Object3D.prototype); return PointLight; })(); </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.
 

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