This repository has been archived by the owner on Oct 23, 2018. It is now read-only.
forked from mishoo/UglifyJS
-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.cola
109 lines (87 loc) · 3.14 KB
/
demo.cola
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// `main` functions may binding to a onload event
// Functions can defined without `function` keyword, with and without `type`
@require './sugar.min.js'
main(){
// Unary operators
// Two variants of `isset` operator. Which is better?
bool _seted = true, _empty;
console.log("`_seted` is", isset _seted ? "seted" : "empty");
console.log("`_empty` is", isset _empty ? "seted" : "empty");
// `clone` operator
Array _first = [584], _second = clone _first;
_first.push(404);
console.log("`_first`:",_first,"`_second`:",_second);
// Binary operators
// `pow` operator
console.log("5 ** 3 =", 5 ** 3);
// `modulo` operator
console.log("10 %% 4 = ", 10 %% 4);
// `isset` conditional assignment
int a, b = 4;
console.log("`a` is", a, ", now `a` is", a ?= b);
console.log("`a` is", a, ", now `a` still", a ?= 584);
// `isset` binary conditional
int x, y = 5;
console.log("`x` is", x, ", `y` is", y, ", x ? y = ", x ? y), x = 1;
console.log("`x` is", x, ", `y` is", y, ", x ? y = ", x ? y);
// `is` operator
console.log("'hello'", "hello" is String ? "is" : "isnt", "`String`");
// `isnt` operator
console.log("'goodby'", "goodby" isnt Number ? "isnt" : "is", "`Number`");
// Boolean alternatives
console.log("`yes` and `no`", yes is Boolean && no is Boolean ? "is" : "isnt", "`Boolean`");
console.log("`on` and `off`", on is Boolean && off is Boolean ? "is" : "isnt", "`Boolean`");
// Strings
// New quotes symbol, multi-lining and templating
console.log(`
Hello!
My name is ColaScript, and i know who you are }:->
User agent: @{navigator.userAgent}
Vendor: {{navigator.vendor}}
`);
// Raw strings
console.log(r"\n \r \t [email protected]");
// Multiline RegExp's
RegExp isEmail = /
([\w-\.]+)
@
((?:[\w]+\.)+)
([a-zA-Z]{2,4})
/;
String email = r'[email protected]';
console.log("@email {{ isEmail.test(email) ? "is" : "isnt" }} valid email adress");
// Arrays
// Empty getter and setter ( pushing )
Array arr = [2, 4, 8, 16, 32];
console.log("Last element of `arr` is", arr[]), arr[] = 64;
console.log("Now last element of `arr` is", arr[]);
// Splice assignment
arr[2..4] = [3, 2, 1];
console.log("`arr` is", arr);
// Range
console.log("`[0..10]` is", [0..10]);
// Calling function
Object pro;
console.log(pro = Profile(
"Dan", "Green", "Russia",
"HTML5", "JavaScript", "Dart", "PHP", "CSS3", "LESS", "Qt",
age : 19,
petName : "Felix"
));
// Cascade operator
pro
..firstName += "iil"
..secondName = "Onoshko"
..skills[1] = "JS";
console.log(pro);
}
// Functions
// Named, positional and splated arguments, with default values.
// Arrow functions.
Object Profile(String firstName, String secondName, String country = "Russia", Array skills..., age:, petName: "Tux"){
skills.forEach((val) => val == "JavaScript" && console.log("JavaScript - It's Awesome!"));
return {
firstName, secondName, age, country, skills, petName
};
}
//main();