Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

First Scripting Language for Web

Name: Anonymous 2013-09-08 22:37

I want to get off my mind of C and ((Scheme)) for a while and learn a scripting language for the web. My professor asked me if I could do a Javascript job for him and I said, I'd have to learn it first.

I want to learn Javascript or CoffeeScript but since the latter is simply a transcompiler for the other, should I learn Javascript first before getting to Coffeescript? I heard Coffeescript often makes more optimized code than Javascript, what if I just learn Coffeescript and submit the transcompiled code to my professor?

Name: Anonymous 2013-09-09 16:10

>>1
CoffeeScript is for people whose first language was Ruby.

# CoffeeScript - Assignment
number = 42
opposite = true

# JavaScript
var cubes, list, math, num, number, opposite, race, square,
__slice = [].slice;

number = 42;

opposite = true;

# CoffeeScript - Conditions
number = -42 if opposite

# JavaScript
if (opposite) {
number = -42;
}

# CoffeeScript - Functions
square = (x) -> x * x

# JavaScript
square = function(x) {
return x * x;
};

# CoffeeScript - Objects
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x

# JavaScript
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
};

# CoffeeScript - Splats
race = (winner, runners...) ->
print winner, runners

# JavaScript
race = function() {
var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners);
};

# CoffeeScript - Existence
alert "I knew it!" if elvis?

# JavaScript
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
}

# CoffeeScript - Array comprehensions
cubes = (math.cube num for num in list)

# JavaScript
cubes = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) {
num = list[_i];
_results.push(math.cube(num));
}
return _results;
})();

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List