I'm using the webgl framework three.js.
Most of the classes can be "cloned" via a .clone()
method.
Wikipedia seems to be very strict when it defines "cloning".
In computer science, cloning refers to the making of an exact copy of an object...
However, i've encountered something like this:
const myClass = new Class()
myClass.foo = 'foo'
myClassClone = myClass.clone()
myClassClone.foo === myClass.foo //true
^ this is what i expect to see out of a "clone".
The documentation for the library does not seem to be consistent though:
https://threejs.org/docs/#api/core/Object3D.clone
Returns a clone of this object and optionally all descendants.
vs.
https://threejs.org/docs/#api/materials/Material.clone
Return a new material with the same parameters as this material.
I'm struggling with the second one because i've encountered something like this
myClass = new Class()
myClass.foo = 'foo'
myClass.bar = 'bar'
myClone = myClass.clone()
myClone.foo === myClass.foo //true
myClone.bar === myClass.bar //false
Depending on what foo and bar are, my clone may or may not behave like the original. It depends on what are considered as these "parameters" but it is still somewhat confusing.
What can i say about this situation.
- Can i use "(non)deterministic" to describe these
.clone()
methods? All of them, some of them? - Are they appropriately named? These never return exact copies of objects since they have
uuid
s, but one seems more "clone-like" than the other. - what other rules and considerations could be made when cloning? Cloning attached event listeners and such may not be the best idea.
threejs
folks chose to use. – Robert Harvey May 08 '18 at 21:42clone()
and nothamburger()
. Likecopy
comes in flavorsdeep
andshallow
, are there more such attributes that a clone could be described with? – Dusan Bosnjak 'pailhead' May 08 '18 at 21:46