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:


Returns a clone of this object and optionally all descendants.



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.

  1. Can i use "(non)deterministic" to describe these .clone() methods? All of them, some of them?
  2. Are they appropriately named? These never return exact copies of objects since they have uuids, but one seems more "clone-like" than the other.
  3. what other rules and considerations could be made when cloning? Cloning attached event listeners and such may not be the best idea.
  • 2
    You're getting stuck on the word "clone." The supreme source of truth for how Clone methods behave is not Wikipedia; it is the associated technology's reference documentation. Whether the name is appropriate or not is irrelevant; that is the name the threejs folks chose to use. – Robert Harvey May 8 '18 at 21:42
  • Are there any best practices when choosing the terminology for an API? There has got to be some logic why this is called clone() and not hamburger(). Like copy comes in flavors deep and shallow, are there more such attributes that a clone could be described with? – Dusan Bosnjak 'pailhead' May 8 '18 at 21:46
  • 2
    All too often, a "best practice" is simply so because someone says it is. Five years later, we've all moved onto something else, and it become the new "best practice." Because of things like "software patterns," many software developers have come to believe that there must be some sort of gold standard for everything that happens in software development, when in fact that's not true at all. Software development is an exercise in tradeoffs; at the end of the day, the "best practice" is usually the one that most effectively meets your specific needs. – Robert Harvey May 8 '18 at 21:57
  • Ok, that sounds like something that can be taken at face value. Still, i'd like to know more terms to be able to describe a phenomenon. – Dusan Bosnjak 'pailhead' May 8 '18 at 22:57
  • There is also the matter of Deep VS Shallow cloning. Deep cloning kills re-usability of objects, but avoids surprises. – S.D. May 9 '18 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.