Skip to content

Instantly share code, notes, and snippets.

@jay3sh
Created Nov 24, 2012
Embed
What would you like to do?
Switch-To-Coffeescript-Code-Snippets
methodfoo : (arg0) ->
func = => x = @someproperty
func()
SomeClass.prototype.methodfoo = function (arg0) {
var thisref = this;
var func = function () {
var x = thisref.someproperty;
}
func();
}
for item in arr
process(item)
for (_i = 0, _len = arr.length; _i < _len; _i++) {
item = arr[_i];
process(item);
}
foo = ({newArg, arg0, arg1}) ->
newArg ?= 42 # default value
foo(arg0:'A', arg1:1)
foo(newArg:24, arg0:'B', arg1:2)
class Person
constructor : ({name}) ->
@name = name
getName : () ->
return @name
class Manager extends Person
getReportingEngineers : () ->
class Engineer extends Person
getManager : () ->
proplist = _(itemlist).map (x)->x.property
proplist = _(itemlist).map(function(x) {
return x.property;
});
"My name is #{@name}. I am #{@age} years old"
"My name is " + this.name + ". I am " + this.age + " years old";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment