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 1 (true) if BaseObj is in Value's chain of base objects, otherwise 0 (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.

Objects, Obj.Base, ObjGetBase, HasMethod, HasProp

Examples

Illustrates the use of this function.

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