Skip to content

Attribute Helpers

let obj = {
    a: 5,
    b: 10
}

if (hasattr(obj, "a")) {
    let v = getattr(obj, "a");
    print(v); // 5
}

These helpers allow explicit attribute inspection and access.

hasattr

let obj = {
    x: 10,
    y: 41
}

if (hasattr(obj, "x")) {
    print("attribute exists!");
}

hasattr checks if a dictionary contains a specificed key. If it does, it returns true, if not then it returns false.

getattr

let obj = {
    x: 10,
    y: 41
}

if (hasattr(obj, "x")) {
    print(getattr(obj, "x"));
}

getattr returns the value inside of a dictionary associated with a specified key. If the value or key does not exist, it returns null.

setattr

let obj = {
    x: 10
}

setattr(obj, "y", 41);
print(obj.y); // 41;
print(getattr("obj", "y")); // 41

setattr adds a new key to the dictionary and assigns a provided value to it.