Quirrel4.41.0

types.String.clone

Method on every string
clone(): any

Returns str itself.

Return value

str unchanged. A Quirrel string is an immutable value, so cloning one has nothing to copy: the VM's Clone falls through to its default: case, which returns the same object instead of allocating a copy (contrast a table or an array, which do allocate a new one).

Notes

Takes no arguments.

clone is a reserved word (it is also the unary clone x operator), and the parser only accepts an identifier after . and .$, so str.clone() and str.$clone() both fail to compile with expected 'IDENTIFIER'. Call this type method through a computed index instead, str["clone"](), or write clone str. With #forbid-clone-operator the word is an ordinary identifier and str.$clone() compiles. types.String.constructor is a reserved word too but the parser special-cases it, so it reads normally as str.constructor.

Example

examples/types/string/clone.nut
// `clone` is a reserved word, so a dotted call does not even parse; reach the
// delegate method through a computed field access instead.
let s = "hello"
println(s["clone"]() == s)
Output:
true

See also

weakrefReturns a weak reference to str.
constructorConverts value to a string. This is what runs when types.String itself is called, types.String(value), the same way types.Integer(value) converts to an integer.
stringclass index