Variables and base types (original) (raw)
Variables definition
You can define vars with any type (yet without checking).
var num = 1;
int i, j = 3;
String str = "someString";
Exists possibility to define object's property:
Also you can mark definition with modificators
:
const myProfile.age = 10;
list of modificators
:
const
to define constantcovert
to define unenumerable property (not var)export
to export var or property from module (read more)
Variables assignment
In ColaScript you can use follow syntax to reduce object filling:
String name = "Felix"; int age = 3; String about = "Black'n'white sly cat.";
Object info = { name, age, about }; // { name: name, age: age, about: about }
Also you can use destructuring assignment
:
int a = 2, b = 3;
[a, b] = [b, a]; // swap { name, age, about, friends : [firstFriend] } = info; // with object [firstSkill, ..., lastSkill] = skills; // with array
Boolean aliases
In ColaScript, like in CoffeScript, exists boolean aliases:
yes == true && on == true; no == false && off == false;
Strings
ColaScript have strings templating! You can paste value of variable in strings:
console.log(my login in twitter \@@twLogin
); // and yes, you can ` quotes
Also we can paste result of expression by this way:
console.log("length of my name @{ name.length }");
and this way:
console.log("first letter in my name is {{ name[0] }}");
It is still possible to use raw strings:
console.log(r"\n\r\t@raw");
Any string in ColaScript is multiline:
console.log(" List1: - Write code - Drink tea - Watch Instagram
List2 * Write code * Read Habrahabr * Listen music ");
align goes by closing-quote.
RegExps
Modifer x
skips whitespaces and new-line
same as if you use multiline RegExp:
// White spaces with x
modifier will be removed.
RegExp isUrl = /^(https?://)? ([\w.]+) .([a-z]{2,6}.?) (/[\w.]*)*/? $/x;
// If regexp contains new-line
then x
modifier will be added automatically
isUrl = /
^
(https?://)?
([\w.]+)
.([a-z]{2,6}.?)
(/[\w.]*)*/?
$/;