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__.

Store a literal in a variable before calling its methods. Direct prototype calls on literals are limited by the current parser.

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.

let greeting = "hello"
println(greeting.length())

Built-in prototypes are frozen. You cannot attach arbitrary methods to a number, string, list, or built-in struct. Define a custom user struct and use impl for its methods. Declared instance fields, dictionary entries, list items, and HTML attributes remain writable through their supported APIs.