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 underscore = angular.module(‘underscore’, []); | |
| underscore.factory(‘_’, function() { | |
| return window._; //Underscore must already be loaded on the page | |
| }); | |
| var app = angular.module(‘app’, ['underscore']); | |
| app.controller(‘MainCtrl’, ['$scope', '_', function($scope, _) { | |
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
| #1) | |
| for name in ["Roger", "Roderick", "Brian"] | |
| alert "Release #{name}" | |
| #2) if you need the current iteration index | |
| for name, i in ["Roger the pickpocket", "Roderick the robber"] | |
| alert "#{i} - Release #{name}" | |
| #3) iterate on one line using the postfix form | |
| release prisoner for prisoner in ["Roger", "Roderick", "Brian"] |
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 true == true | |
| "we are ok" | |
| if true != true then "panic" | |
| #There is no ternary in Coffeescript | |
| # (i > 0) ? "OK" : "Not OK" | |
| if i > 0 then "OK" else "Not OK" | |
| (or) | |
| if i > 0 then "OK" |
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
| array1 = [1, 2, 3] | |
| array2 = [ | |
| 1 | |
| 2 | |
| 3 | |
| ] | |
| array3 = [1,2,3,] |
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
| @saviour = true | |
| # prototype | |
| User::first = ->@record[0] | |
| # existential operator (?) | |
| praise if brain? | |
| # existential operator (?) in place of || operator | |
| velocity = southern ? 40 |