Quirrel4.41.0

types.Instance.hasindex

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

Tests whether key names a field or method reachable on this instance.

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 key is one of the instance's own fields or one of its class's methods, false otherwise.

Notes

Marked pure. Unlike a table, an instance's methods live on its class rather than in a separate delegate, and hasindex/rawget/rawin all see them directly: they are not something "raw" access skips here.

Example

examples/types/instance/hasindex.nut
class Foo {
  x = 1
  function bar() { return 2 }
}
let f = Foo()
println("f.hasindex(\"x\") =", f.hasindex("x"))
println("f.hasindex(\"bar\") =", f.hasindex("bar"))
println("f.hasindex(\"z\") =", f.hasindex("z"))
Output:
f.hasindex("x") = true
f.hasindex("bar") = true
f.hasindex("z") = false

See also

rawinTests whether key names a field or method reachable on this instance.
rawgetReads the value stored at key on this instance, without consulting a _get metamethod.
hasindexTests whether key names a member of the class.
instanceclass index