Last active
December 17, 2015 06:08
-
-
Save devopsmariocom/5563064 to your computer and use it in GitHub Desktop.
Javascript vs CoffeScript
This file contains hidden or 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
if x? then use(x) | |
cupsOfCoffee ?= 0 | |
coffeePot?.brew() |
This file contains hidden or 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
if (typeof x !== "undefined" && x !== null) { | |
use(x); | |
} | |
if (cupsOfCoffee == null) { | |
cupsOfCoffee = 0; | |
} | |
if (typeof coffeePot !== "undefined" && coffeePot !== null) { | |
coffeePot.brew(); | |
} |
This file contains hidden or 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
var developers; | |
developers = { | |
mario: { | |
xxx: 'yyy' | |
}, | |
alex: { | |
jjj: 'www' | |
}, | |
beguene: { | |
ttt: 'rrr' | |
}, | |
greeting: function() { | |
return alert('hey!'); | |
} | |
}; |
This file contains hidden or 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
developers = | |
mario: | |
xxx: | |
'yyy' | |
alex: | |
jjj: | |
'www' | |
beguene: | |
ttt: | |
'rrr' | |
greeting: -> | |
alert 'hey!' |
This file contains hidden or 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
# This will simply create array of attributes names | |
attributes_name = (attribute.name for attribute in Attribute.all()) | |
# run console.log for each attribute name | |
console.log attribute.name for attribute in Attribute.all() | |
# run console.log for each split attribute.name | |
console.log attribute.name for attribute in Attribute.all() when attribute.is_split? |
This file contains hidden or 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
var attribute, attributes_name; | |
attributes_name = (function() { | |
var _i, _len, _ref, _results; | |
_ref = Attribute.all(); | |
_results = []; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
attribute = _ref[_i]; | |
_results.push(attribute.name); | |
} | |
return _results; | |
})(); | |
_ref = Attribute.all(); | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
attribute = _ref[_i]; | |
console.log(attribute.name); | |
} | |
var attribute, _i, _len, _ref; | |
_ref = Attribute.all(); | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
attribute = _ref[_i]; | |
if (attribute.is_split != null) { | |
console.log(attribute.name); | |
} | |
} |
This file contains hidden or 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
class Coffee | |
constructor: (@name, @strength=1) -> | |
brew: -> alert "brewing #{@name}" | |
class MaxgoodHouse extends Coffee | |
constructor: (@name, @strength=0) -> | |
@brand = "Maxgood House" | |
boring = new MaxgoodHouse("Boring") | |
boring.brew() |
This file contains hidden or 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
var Coffee, MaxgoodHouse, boring, | |
__hasProp = {}.hasOwnProperty, | |
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | |
Coffee = (function() { | |
function Coffee(name, strength) { | |
this.name = name; | |
this.strength = strength != null ? strength : 1; | |
} | |
Coffee.prototype.brew = function() { | |
return alert("brewing " + this.name); | |
}; | |
return Coffee; | |
})(); | |
MaxgoodHouse = (function(_super) { | |
__extends(MaxgoodHouse, _super); | |
function MaxgoodHouse(name, strength) { | |
this.name = name; | |
this.strength = strength != null ? strength : 0; | |
} | |
MaxgoodHouse.brand = "Maxgood House"; | |
return MaxgoodHouse; | |
})(Coffee); | |
boring = new MaxgoodHouse("Boring"); | |
boring.brew(); |
This file contains hidden or 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
for i in [0..10] | |
console.log i | |
#slicing | |
myArray[2..5] |
This file contains hidden or 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
for (i = _j = 0; _j <= 10; i = ++_j) { | |
console.log(i); | |
} | |
myArray.slice(2, 6); |
This file contains hidden or 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
# no awkward '+' joining | |
error ( message ) -> | |
alert "Hey here is #{message}" |
This file contains hidden or 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
error(function(message) { | |
return alert("Hey here is " + message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment