For those who prefer Python over JavaScript and think CoffeeScript feels more like Perl
In English, a comma is a more significant delimiter than a space
Not In coffeescript, however
>>> Not In coffeescript, however
Not(In(coffeescript, however));CoffeeScript
JavaScript
doSomething 1,
2
3
4doSomething(1, 2, 3, 4);doSomething 1,
2
3
4doSomething(1, 2);
3;
4;doSomething 1,
2
3
4doSomething(1, 2, 3, 4);What does the following code do?
doNothing = (i) ->
x = (n) ->
for i in [0...n]
doNothing i
x 1e20It crashes!
doNothing = function(i) {};
x = function(n) {
var i, j, ref, results;
results = [];
for (i = j = 0, ref = n; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
results.push(doNothing(i));
}
return results;
};
x(1e20);CoffeeScript conceals details that could lead to serious bugs
Another implicit return victim:
nextState = off
totalClicks = 0
$ ->
#Count how many button clicks there have been
$('form').submit ->
totalClicks++
$('#total').text totalClicks
false
#Toggle when the toggle button is clicked
$('#btn').click ->
$('#state').text if nextState then "On" else "Off"
nextState = !nextStateclass Rectangle:
def __init__(self, w=1, h=1):
self.width = w
self.height = h
def getArea(self):
return self.width*self.height
@staticmethod
def isRectangle(object):
return isinstance(object, this)
a = Rectangle(5, 10)
a.getArea() == Rectangle.getArea(a)
print(Rectangle.isRectangle(a))function _$rapyd$_print() {
var args, output;
args = [].slice.call(arguments, 0);
output = JSON.stringify(args);
if ("console" in window) console.log(output.substr(1, output.length-2));
}
function Rectangle() {
this.__init__.apply(this, arguments);
}
Rectangle.prototype.__init__ = function __init__(w, h){
var self = this;
if (typeof w === "undefined") w = 1;
if (typeof h === "undefined") h = 1;
self.width = w;
self.height = h;
};
Rectangle.prototype.getArea = function getArea(){
var self = this;
return self.width * self.height;
};
Rectangle.isRectangle = function isRectangle(object){
return object instanceof this;
};
a = new Rectangle(5, 10);
a.getArea() === Rectangle.prototype.getArea.call(a);
_$rapyd$_print(Rectangle.isRectangle(a));Write your next web app in RapydScript