Skip to content Skip to sidebar Skip to footer

What Is The Benefit Of Using Extend On The Prototype In Three.js Inheritance Pattern?

Working with the excellent Three.js framework and currently looking for a good javascript inheritance pattern, I had a look to what is done in Three.js. I now have a good understan

Solution 1:

Why are some methods directly added to the prototype and some are added using THREE.extend

Seriously, it doesn't make any sense.

As you can find out in the blame view, @mrdoob introduced this oddity with revision cc57273. The commit message says:

Reverting to Object.prototype = { pattern. Only using it on the methods that really need it.

Misteriously when using the latest version of the lib on the project I'm working on I'm getting this error:

> Uncaught TypeError: Object [objectObject] has no method 'set'

This is caused when THREE.UniformsLib.common.diffuse initialises a THREE.Color (THREE.Color.set() seems to be undefined then). For some reason this only happens when I load Box2D before three.js. If I load it after is all good. But this fixes the problem too.

This is reverting commit e2df06e by @bhouston where extend was introduced:

fix three missed conversions to closures. switch to extending math prototypes rather than replacing them. This is to ensure that types created in closures within a type's prototype definition get their prototype updated with the full definition.

Post a Comment for "What Is The Benefit Of Using Extend On The Prototype In Three.js Inheritance Pattern?"