UglifyJS/demo.cola

111 lines
3.2 KiB
Plaintext
Raw Normal View History

2014-04-28 08:20:12 +00:00
// `main` functions may binding to a onload event
// Functions can defined without `function` keyword, with and without `type`
2014-05-26 12:43:41 +00:00
@require './sugar.min.js'
2014-04-16 16:43:40 +00:00
2014-05-21 18:01:32 +00:00
main(){
2014-04-28 08:20:12 +00:00
// Unary operators
// Two variants of `isset` operator. Which is better?
bool _seted = true, _empty;
console.log("`_seted` is", _seted?? ? "seted" : "empty");
console.log("`_empty` is", isset _empty ? "seted" : "empty");
2014-04-16 16:43:40 +00:00
2014-04-28 08:20:12 +00:00
// `clone` operator
Array _first = [584], _second = clone _first;
_first.push(404);
console.log("`_first`:",_first,"`_second`:",_second);
2014-04-16 16:43:40 +00:00
2014-04-28 08:20:12 +00:00
// Binary operators
// `pow` operator
console.log("5 ** 3 =", 5 ** 3);
2014-04-16 16:43:40 +00:00
2014-04-28 08:20:12 +00:00
// `modulo` operator
console.log("10 %% 4 = ", 10 %% 4);
2014-04-16 16:43:40 +00:00
// `isset` conditional assignment
2014-04-28 08:20:12 +00:00
int a, b = 4;
console.log("`a` is", a, ", now `a` is", a ?= b);
console.log("`a` is", a, ", now `a` still", a ?= 584);
2014-04-16 16:43:40 +00:00
2014-04-28 08:20:12 +00:00
// `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);
2014-04-18 18:33:08 +00:00
2014-04-28 08:20:12 +00:00
// `is` operator
console.log("'hello'", "hello" is String ? "is" : "isnt", "`String`");
2014-04-28 08:20:12 +00:00
// `isnt` operator
console.log("'goodby'", "goodby" isnt Number ? "isnt" : "is", "`Number`");
2014-04-28 08:20:12 +00:00
// 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`");
2014-04-28 08:20:12 +00:00
// Strings
// New quotes symbol, multi-lining and templating
console.log(`
2014-04-28 08:20:12 +00:00
Hello!
My name is ColaScript, and i know who you are }:->
User agent: @{navigator.userAgent}
Vendor: {{navigator.vendor}}
2014-04-18 18:33:08 +00:00
2014-04-28 08:20:12 +00:00
`);
2014-04-16 16:43:40 +00:00
2014-04-28 08:20:12 +00:00
// Raw strings
console.log(r"\n \r \t some@email.ru");
2014-04-16 16:43:40 +00:00
2014-04-28 08:20:12 +00:00
// Multiline RegExp's
2014-04-18 18:33:08 +00:00
RegExp isEmail = /
2014-04-16 16:43:40 +00:00
([\w-\.]+)
@
((?:[\w]+\.)+)
([a-zA-Z]{2,4})
2014-04-28 08:20:12 +00:00
/;
String email = r'some@email.ru';
console.log("@email {{ isEmail.test(email) ? "is" : "isnt" }} valid email adress");
// Arrays
// Empty getter and setter ( pushing )
2014-04-28 08:20:12 +00:00
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
2014-04-28 08:20:12 +00:00
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",
2014-04-28 08:20:12 +00:00
"HTML5", "JavaScript", "Dart", "PHP", "CSS3", "LESS", "Qt",
age : 19,
petName : "Felix"
));
// Cascade operator
pro
..firstName += "iil"
..secondName = "Onoshko"
..skills:
..[1] = "JS";
;
console.log(pro);
2014-04-16 16:43:40 +00:00
}
2014-04-28 08:20:12 +00:00
// 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 Awesome!"));
return {
2014-05-21 18:01:32 +00:00
firstName, secondName, age, country, skills, petName
2014-04-28 08:20:12 +00:00
};
}
2014-05-19 17:29:01 +00:00
//main();