Created
March 11, 2012 12:23
-
-
Save benshimmin/2016246 to your computer and use it in GitHub Desktop.
Nice pattern for utility classes in CoffeeScript
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
Utils = | |
Math : | |
class MathUtils | |
@clamp : (num, min, max) -> | |
return min if num < min | |
return max if num > max | |
num | |
String : | |
class StringUtils | |
@trimLeft : (str) -> | |
str.replace /^\s+/, "" | |
@trimRight : (str) -> | |
str.replace /\s+$/, "" | |
(exports ? @).Utils = Utils |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment