0

I'm trying to use Babylon.js in an Ember app and am getting errors related to the Ember extending the Array prototype (something Babylon does too) conflicting. Specific error in Babylon:

Uncaught TypeError: renderingGroup.prepare is not a function

I created an Ember CLI addon with Babylon.js as a dependency (with prototype extensions disabled) and it works when testing within the addon's dummy app.

Once I import the addon into my existing app (with prototype extensions enabled), it once again breaks (serving up the same error). Can the addon be isolated with its dependencies (maintaining prototype extensions disabled) once installed into an app the has prototype extensions enabled? Are there any other possible solutions to getting Bablyon.js working in Ember? Thanks.

1 Answers1

1

You will have to disable prototype extensions in the importing app too.

"Array protoype extensions" are a global modification, you can't isolate them within an addon. Once the prototype of an array has been modified, it will be modified for absolutely every single instance of an array. It doesn't matter if it lives in an Ember app, JQuery or a <script> tag in your body.

see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

Maybe you could try to use prototype extensions added by Ember and Babylon in such a way that they don't conflict with each other... sure it sounds like a lot of work...

givanse
  • 14,503
  • 8
  • 51
  • 75
  • 1
    Thanks givanse, I finally got it working last night doing exactly what you suggest. I added a more detailed how-to in the Babylon issue on github: [https://github.com/BabylonJS/Babylon.js/issues/474](https://github.com/BabylonJS/Babylon.js/issues/474) – DanLeininger Apr 22 '15 at 14:33