alteredq/three.js — comment on commit baf0f65e1db76cc95e3d1a3cf759861b807fa177
File:  line 0
By alteredq:

I'm aware of this and I'm not sure.

I don't know what's a proper way to handle these. You definitely do not want to internally `clone` / `new` / `[]` / `{}` unless really unavoidable (i.e. when stuff created this way will stay; you don't want side-effect of methods spawning new objects just to be thrown away).

I solved it like this here as this is how we do this elsewhere, so at least it's consistent. And you are absolutely right that this could lead to some hard to track bugs, if you don't know what's going on.

With this pattern it's always responsibility of caller to do a local copy of the value if it's not used right away:

```javascript
var relative = object.position.relativeToAbsolute( object2 ).clone();
var absolute = object.position.absoluteToRelative( object3 ).clone();
```

Or if you do this in a loop and you need to keep intermediate results:

```javascript
relative.copy( object.position.relativeToAbsolute( object2 ) );
absolute.copy( object.position.absoluteToRelative( object3 ) );
```

So far this worked ok, just you need to be aware it works like this (so far there was a single issue posted and poster figured it out himself).

I chose this solution as lesser evil because everything will eventually end up being called in the loop and will cause garbage collection hickups.

If we hardcode cloning inside, there is no way how not to have it. While if we return internal variables, we still can achieve the same effect in other way.

Another option I considered was to have second parameter, which if undefined would lead to creating clone:

```javascript
var relative = new THREE.Vector3();

// this would use supplied vector
object.position.relativeToAbsolute( object, relative );
```

```javascript
// this would create clone
var relative = object.position.relativeToAbsolute( object );
```

But this is somehow uglier API (and inconsistent with how we deal with this issue elsewhere). Also if we switched to this, it would promote inefficient code. Everybody would end up doing clones everywhere simply because it looks neater.