HasBase

Returns a non-zero number if the specified value is derived from the specified base object.

HasBase := HasBase(Value, BaseObj)

Parameters

Value

Any value, of any type.

BaseObj

Type: Object

The potential base object to test.

Return Value

Type: Integer (boolean)

This function returns true if BaseObj is in Value's chain of base objects, otherwise false.

Remarks

The following code is roughly equivalent to this function:

MyHasBase(Value, BaseObj) {
    b := Value
    while b := ObjGetBase(b)
        if b = BaseObj
            return true
    return false
}

For example, HasBase(Obj, Array.Prototype) is true if Obj is an instance of Array or any derived class. This the same check performed by Obj is Array; however, instances can be based on other instances, whereas is requires a Class.

HasBase accepts both objects and primitive values. For example, HasBase(1, 0.base) returns true.

Since COM objects are not derived from any AutoHotkey object, HasBase always returns 0 if given a ComObject.

Related

Objects, Obj.Base, ObjGetBase, HasMethod, HasProp

Examples

#1

thebase := {key: "value"}
derived := {base: thebase}
MsgBox HasBase(thebase, derived) ; 0
MsgBox HasBase(derived, thebase) ; 1