Skip to content
This repository was archived by the owner on Oct 23, 2018. It is now read-only.

Classes and singletons

dangreen edited this page Jan 2, 2015 · 5 revisions

Classes in ColaScript looks like classes from Dart:

  • Exists named contructors
  • It is not necessary to use this context
  • super context to call parent methods

But in ColaScript classes:

  • exists self alias of class context
  • you can "run" any code in class, it will be pushed in constructors
class ListData {
    covert Array listData = [];
    static const String About = "Example of class";

    $("#btn").click(() => alert(About));

    ListData(Array data) {
        listData = data;
    }

    ListData.fromString(String text) {
        listData = text.split('\n');
    }

    Array get data() {
        console.log(About);
        return listData;
    }

    set data(Array data) {
        listData = data;

        $("#list-title").html(About);
        data.forEach((el){
            $("#list").append("<li>@el</li>");
        });
    }
}

console.log(ListData::About);

To not use this context for parents props you should redefine props.

class DataList extends ListData {
    covert Array listData;
    static const String About;

    DataList.fromString(String text) {
        console.log(text);
        super.fromString(text);
    }
}
Clone this wiki locally