Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (73 sloc) 1.44 KB
# Assignment
language = "Jack"
cool = ok
Animal = {legs=4 eyes=2}
# Loops over objects/arrays
for key, value in myObj if true
# ...
end
# Compiles to:
#
# var key, value;
# for (key in myObj) {
# if (myObj.hasOwnProperty(key) && true) {
# value = myObj[key];
# # ...
# }
# }
# Array comprehensions
[item for item in myList if item]
# Compiles to:
# myList.filter(function (item) {
# return item;
# }).map(function (item) {
# return item;
# });
# Object comprehensions
{value for key, value in myObj unless value.length < 2}
# Compiles to:
#
# Object.comprehension(myObj, function(key, value) {
# return value;
# }, function (key, value) {
# return key.length < 2
# });
#
# OR:
#
# (function () {
# var newobj = {}, key, value;
# for (key in myObj) {
# value = myObj[key];
# if (myObj.hasOwnProperty(key) && !(key.length < 2)) {
# newobj[key] = value;
# }
# }
# return newobj;
# }());
# Long test
long = {one=1 two=2 three=3 four=4 five=5 six=6 seven=7 eight=8 nine=9 ten=10}
[
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
]
[1,2,3,4,5]
# Postfix conditionals
do = ok if false
do = no unless true
# Conditionals
if strange_stuff
Octocat = {Animal legs=8}
else
Cat = {Animal}
end
# Inverse conditional
unless opposite_day
day = false
end
square = fun x ->
x = true
Cat = false
newvar = no
end