Quirrel4.41.0

types.Class.hasindex

Method on every class
pure class.hasindex(key): any

Tests whether key names a member of the class.

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.

Parameters

keyanythe member name to test for

Return value

true if the class has an own member called key, false otherwise.

Notes

Marked pure. Behaves the same as rawin here: a class has no delegate of its own for indexing to bypass, so there is nothing "hasindex" skips that plain lookup would not. A derived class's inherited members count too, since they are copied into its own member table when the class is declared.

Example

examples/types/class/hasindex.nut
class Foo { x = 1 }
println("Foo.hasindex(\"x\") =", Foo.hasindex("x"))
println("Foo.hasindex(\"y\") =", Foo.hasindex("y"))
Output:
Foo.hasindex("x") = true
Foo.hasindex("y") = false

See also

rawinTests whether key names a member of the class.
rawgetReads the value stored at key in the class's own member table.
hasindexTests whether key names a field or method reachable on this instance.
classclass index