Skip to content

Instantly share code, notes, and snippets.

@ybiquitous
Created July 23, 2012 09:27
Show Gist options
  • Save ybiquitous/3162796 to your computer and use it in GitHub Desktop.
Save ybiquitous/3162796 to your computer and use it in GitHub Desktop.
CoffeeScript+Underscore.js+jQuery
jQuery ($) ->
nums = [20..0]
doms = _.map nums, (e, i, l) -> "<li>[#{i}]=#{e}</li>"
$("<ul>#{doms.join("")}</ul>").appendTo("body")
hoge =
name: "Hoge"
age: 10
$("<p>").text("Name: #{hoge.name}, Age: #{hoge.age}").appendTo("body")
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Test Coffeescript</title>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script src="test.js"></script>
</head>
<body>
</body>
</html>
// Generated by CoffeeScript 1.3.3
(function() {
jQuery(function($) {
var doms, hoge, nums;
nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
doms = _.map(nums, function(e, i, l) {
return "<li>[" + i + "]=" + e + "</li>";
});
$("<ul>" + (doms.join("")) + "</ul>").appendTo("body");
hoge = {
name: "Hoge",
age: 10
};
return $("<p>").text("Name: " + hoge.name + ", Age: " + hoge.age).appendTo("body");
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment