Skip to content

Type Prototypes

Nubo values can have functions attached to them through type prototypes.

A prototype is like a method table for a value. It lets you call functions directly on values:

let s = "hello"
println(s.length())
println(s.toUpperCase())

This means many values in Nubo are not just raw data. They can expose useful behavior.

PageDescription
StringsString helpers like length, includes, split, trim, and case conversion.
ListsList helpers like push, pop, map, filter, slice, and indexed access.
DictionariesDictionary helpers like keys, values, remove, and indexed access.
IntegersInteger helpers like increment and decrement.
HTML ElementsAttribute and children helpers for html values.
FunctionsFunction metadata and initialized calls.
StructsStruct fields, methods, private fields, and special hooks.
Internal HooksInternal names like __get__, __set__, __args__, and __returns__.

Prototype calls currently work reliably on values stored in variables.

let s = "string"
println(s.length())

Calling prototype methods directly on literals is currently limited by AST/parser behavior.

// Currently may not work:
println("string".length())

Prefer assigning the literal to a variable first.

let text = "string"
println(text.length())

Use prototype methods when they make code easier to read.

let text = "a,b,c"
let parts = text.split(",")
println(parts)

Avoid direct literal method calls until AST support is complete.

// Avoid for now:
println("hello".length())