Note: information on this page refers to Ceylon 1.0, not to the current release.
- Lexical scope, which is the default, and
- Prototype style, also known as optimized.
Lexical scope style
In lexical scope style, a type´s methods and attributes are assigned to each new instance as it is created. This offers good encapsulation but incurs in some performance costs.
A Ceylon module is compiled as a CommonJS module, but since this format has no notion of packages, all the packages in the Ceylon module will be contained in the same CommonJS file. To avoid naming collisions, there are some rules used when generating names for top-level declarations:
- If the declaration is in the module´s root package, then its name is basically the same.
- If the declaration is in a subpackage, its name will have the subpackage name appended to it.
For example, for a module
my.module the declaration
my.module.MyClass will simply
my.module.sub1.sub2.MyClass will be called
can be important, especially when mixing native code with code generated by the compiler.
You can mix native code simply by adding a
.js file to the list of sources to be compiled, for example:
ceylon compile-js unit1.ceylon unit2.ceylon some_native_stuff.js unit3.ceylon
The compiler will generate a CommonJS module containing the results of processing
unit2.ceylon, then copying the contents of
and finally processing
When compiling for the JVM, any top-level method can be used as an entry point to
run a program. The default is
run but you can specify any other top-level method.
shared top-level methods can be used as entry
points to run a program with the
run-js command. This is because a command is executed
that loads the specified module and runs the specified method from it, and since only
shared top-level declarations are directly added to the
exports object of the
CommonJS module, only a
shared top-level method can be run.