Last active
January 3, 2016 15:49
-
-
Save wlyecn/8485182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function | |
square = (x) -> x * x | |
fill = (container, liquid = "coffee") -> | |
"Filling the #{container} with #{liquid}..." | |
### JavaScirpt | |
var fill, square; | |
square = function(x) { | |
return x * x; | |
}; | |
fill = function(container, liquid) { | |
if (liquid == null) { | |
liquid = "coffee"; | |
} | |
return "Filling the " + container + " with " + liquid + "..."; | |
}; | |
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# value | |
kids = | |
brother: | |
name: "Max" | |
age: 11 | |
sister: | |
name: "Ida" | |
age: 9 | |
### JavaScirpt | |
var kids; | |
kids = { | |
brother: { | |
name: "Max", | |
age: 11 | |
}, | |
sister: { | |
name: "Ida", | |
age: 9 | |
} | |
}; | |
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# array | |
list = [1, 2, 3, 4, 5] | |
cubes = (math.cube num for num in list) | |
copy = list[0...list.length] | |
countdown = (num for num in [10..1]) | |
### JavaScript | |
var copy, countdown, cubes, list, num; | |
list = [1, 2, 3, 4, 5]; | |
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; | |
})(); | |
copy = list.slice(0, list.length); | |
countdown = (function() { | |
var _i, _results; | |
_results = []; | |
for (num = _i = 10; _i >= 1; num = --_i) { | |
_results.push(num); | |
} | |
return _results; | |
})(); | |
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CoffeeScript ready | |
$-> | |
some() | |
init() | |
calls() | |
### JavaScript | |
$(document).ready(function() { | |
some(); | |
init(); | |
calls(); | |
}) | |
### | |
# CoffeeScript ready v2 | |
jQuery ($) -> | |
# your code here! | |
### JavaScript | |
jQuery(function($) { | |
// your code here! | |
}); | |
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CoffeeScript | |
formValues = (elem.value for elem in $('.input')) | |
### JavaScript | |
var elem, formValues; | |
formValues = (function() { | |
var _i, _len, _ref, _results; | |
_ref = $('.input'); | |
_results = []; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
elem = _ref[_i]; | |
_results.push(elem.value); | |
} | |
return _results; | |
})(); | |
### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CoffeeScript | |
object = | |
func: -> $('#div').click => @element.css color: 'red' | |
### JavaScript | |
var object; | |
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
object = { | |
func: function() { | |
return $('#div').click(__bind(function() { | |
return this.element.css({ | |
color: 'red' | |
}); | |
}, this)); | |
} | |
}; | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment