Created
          August 29, 2011 22:01 
        
      - 
      
- 
        Save brendanberg/1179527 to your computer and use it in GitHub Desktop. 
    Making objects using closures 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
    
  
  
    
  | point = (x, y) -> | |
| setX = (nx) -> x = nx | |
| setY = (ny) -> y = ny | |
| (n) -> n(x, y, setX, setY) | |
| pointGetX = -> | |
| (x, y) -> x | |
| pointGetY = -> | |
| (x, y) -> y | |
| pointAdd = (p2) -> | |
| (x, y, setX, setY) -> | |
| setX(x + p2 pointGetX()) | |
| setY(y + p2 pointGetY()) | |
| p1 = point(1, 2) | |
| p2 = point(3, 5) | |
| println (p1 pointGetX()) + ',' + p1(pointGetY()) | |
| println (p2 pointGetX()) + ',' + p2(pointGetY()) | |
| p1(pointAdd(p2)) | |
| println '---' | |
| println p1(pointGetX()) + ',' + p1(pointGetY()) | 
        
      
            nasser
  
      
      
      commented 
        Jan 21, 2012 
      
    
  
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment