clone undefined

Our clone functions throw a DeveloperError if the source is undefined, e.g.,

BoundingSphere.clone = function(sphere, result) {

if (typeof sphere === ‘undefined’) {

throw new DeveloperError(‘sphere is required’);


This forces us to check if the source may be undefined, e.g.,

if (typeof this.boundingSphere !== ‘undefined’) {

BoundingSphere.clone(this.boundingSphere, result.boundingSphere);

} else {

result.boundingSphere = undefined;


Let’s just return undefined if the source is undefined. It makes sense in the context of cloning. Other thoughts? This will be a good issue to label as “beginner.”


If cloning something regardless of whether it’s defined or not is the “standard use case”, then I have no problem with this change. While it’s a little non-standard compared to the rest of our functions, your reasoning makes sense.

One concern is that it has to the potential to set a scratch variable to undefined:

scratchBoundingSphere = BoundingSphere.clone(sphere, scratchBoundingSphere);

That wouldn’t cause a bug, but would cause a (small?) performance problem. Previously it would be more obvious because you’d have to explicitly write code that sets it to undefined.

Of course, this pattern is fine, so maybe I’m just paranoid:

var boundingSphere = BoundingSphere.clone(sphere, scratchBoundingSphere);


I’ll go with paranoid. lol.

Any other concerns? This also mimics the behavior of the assignment operator, which does not throw with “sphere = undefined.”


I submitted #864 for this.