I'm feeling a bit confused about my understanding of Objects, prototypes, require.js and three.js. Let me illustrate with an example:
In Summary:
The instance "wee" is derived from "Wee," which acts as a wrapper or monkey patch for THREE...
Shouldn't "wee" then inherit properties and methods from THREE?
(Using the transitive property: a = b = c; therefore a = c.)
define (['three'], function () {
function WEE(){
THREE;
return THREE;
}
var test = new WEE;
console.log("test");
console.log(test);
function Wee(){
WEE.call(this);
this.prototype = new WEE();
this.width = window.innerWidth;
this.height = window.innerHeight;
this.aspectRatio = window.innerWidth / window.innerHeight;
}
var wee = new Wee();
console.log("wee");
console.log(wee);
});
This is where I start to get puzzled...
The 'test' log in Chrome displays:
test
Object {REVISION: "66", CullFaceNone: 0, CullFaceBack: 1, CullFaceFront: 2, CullFaceFrontBack: 3...}
which seems correct. My intention was to create a custom version of three.js.
However, when I log 'wee' in Chrome, it shows:
wee
Wee {prototype: Object, width: 1920, height: 1102, aspectRatio: 1.7422867513611615}
Looking into the prototype details, I can see that the prototype is Wee, which relates to THREE- which is also good... but what's confusing me is when I proceed with this piece of code:
var renderer = new wee.WebGLRenderer();
and it gives back "undefined".
I've also attempted:
var renderer = wee.WebGLRenderer;
var renderer = wee.WebGLRenderer();
but all attempts fail with "Uncaught TypeError: undefined is not a function."
Questions:
- What could be happening here?
- What key element am I overlooking?
- Why does THREE actually work initially, given that my define function requires it but doesn't assign it anywhere?
- Am I even asking the right question? Is there a better way to phrase it so I can search for answers more effectively next time?