Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (35 sloc) 1.08 KB
description
A class for this, a class for that.

Classes

Classes are the lifeblood of object-oriented programming. Caboose has full support for classes and objects!

Defining a Class

Classes provide the basis for object creation in Caboose

{% code-tabs %} {% code-tabs-item title="example_class_definition.cb" %}

class SomeClass {
    // Constructor
    init() {
        println("Object created!");
    }
}

SomeClass(); // Prints "Object created!"

{% endcode-tabs-item %} {% endcode-tabs %}

Constructor

init() is the name for a constructor in Caboose. A constructor is a method that is called when an object is instantiated. Instantiating an object is just like invoking a function, except you “invoke” the class. You can also pass arguments to the constructor to be used.

{% code-tabs %} {% code-tabs-item title="example_class_constructor.cb" %}

class SomeClass {
    // Constructor
    init(message) {
        println(message);
    }
}

SomeClass("Object created!"); // Prints "Object created!"

{% endcode-tabs-item %} {% endcode-tabs %}

You can’t perform that action at this time.