Property accessors (original) (raw)

In Cola you have access to elements of array via dot accessor:

console.log([0..10].5) // 5

From Dart was taken cascade accessor:

document.querySelector("#myelement").style ..fontSize = "16px" ..color = "black"

but ColaScript have some modification:

document.querySelector("#myelement") ..style: ..fontSize = "16px" ..color = "black"; ..innerHTML = "Hello World!"

and in ColaScript you can define a function in cascade:

FileReader reader = new FileReader()..onload(loadEvent) {...}

From CoffeeScript was taken prototype accessor:

Array::forEach.call([0..9], () => console.log())

String String::replaceAll(a, b) { String res = this

while res.indexOf(a) != -1 {
    res = res.replace(a, b)
}

return res

}

Also from CoffeeScript was taken conditional accessor:

console.log(someObj?.test()); // undefined

var someObj = { test: () => "test called" };

console.log(someObj?.test()) // "test called"