GLTFParser.prototype.loadMeshes and GLTFParser.prototype.loadNodes use for...in loops.
Since a for...in loop in JavaScript iterates over an objects properties, these can cause the parse to fail if there is a custom property added to the Array object elsewhere on the site. For example, in GLTFParser.prototype.loadMeshes there is:
for ( var name in primitives ) {
var primitive = primitives[ name ];
var geometry = geometries[ name ];
If another script does something like:
Array.prototype.newCustomProp = function (num) {
}
Then eventually name would equal newCustomProp and the attempt to find primitive/geometry will fail.
It is bad practice to extend the base prototypes of JavaScript.
Read this for more information: Maintainable JavaScript: Don鈥檛 modify objects you don鈥檛 own
Also see #11972
If another script does something like:
Array.prototype.newCustomProp = function (num) {}
If you ever see someone doing that, invite him to quite the javascript world please 馃槈
However, if primitives is an array, we shouldn't use for in.
/cc @donmccurdy
Array.prototype.newCustomProp = function (num) {}
If you ever see someone doing that, invite him to quite the javascript world please
The market is full of software "developers" these days.
Next time they might start to prototype the Java Island and the Java Sea.
Most of these for...in loops are left from glTF 1.0, which used object syntax for a lot of things. We can replace them with traditional for loops yes.
Most helpful comment
If you ever see someone doing that, invite him to quite the javascript world please 馃槈