Defines a type T that is cloneable, capable of being duplicated either
implicitly as a Primitive or explicitly via a Clone implementation.
The Cloneable type encompasses all values that can be cloned into a new,
independent instance. It is a union of:
Primitive type: JavaScript primitives (e.g., number,
string, boolean) that are inherently copied by value through assignment.
Clone types: Types that provide an explicit clone() method to create
a duplicate instance of T.
Inspired by Rust's distinction between Copy and Clone, this type captures:
Implicit cloning: For Primitive types, where assignment
(e.g., let y = x) creates a new copy due to their value semantics.
Explicit cloning: For Clone types, where a clone() method must be
invoked to produce a new instance.
This type is broader than Clone alone, as it includes both implicitly
copyable primitives and explicitly cloneable types. For
non-primitive types, the clone() method should return a distinct instance,
though the depth of the copy (shallow or deep) depends on the implementation.
Defines a type
T
that is cloneable, capable of being duplicated either implicitly as a Primitive or explicitly via a Clone implementation.The Cloneable type encompasses all values that can be cloned into a new, independent instance. It is a union of:
number
,string
,boolean
) that are inherently copied by value through assignment.clone()
method to create a duplicate instance ofT
.Inspired by Rust's distinction between
Copy
andClone
, this type captures:let y = x
) creates a new copy due to their value semantics.clone()
method must be invoked to produce a new instance.This type is broader than Clone alone, as it includes both implicitly copyable primitives and explicitly cloneable types. For non-primitive types, the
clone()
method should return a distinct instance, though the depth of the copy (shallow or deep) depends on the implementation.Example