Created
February 18, 2012 02:08
-
-
Save geraldalewis/1856904 to your computer and use it in GitHub Desktop.
Implicit `this` in CoffeeScript
This file contains 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 Sprite | |
@id: 0 | |
id: -1 | |
x: 0 | |
y: 0 | |
width: 0 | |
height: 0 | |
constructor: -> | |
id = ++Sprite.id # ~> this.id = ++Sprite.id | |
move: (x,y) -> | |
this.x = x | |
this.y = y | |
# `this` is sometimes still useful/necessary (identical params/class body vars) | |
getRect: -> | |
new Rectangle x, y, width, height | |
# ~> new Rectangle this.x, this.y, this.width, this.height | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting... Time for me to finally finish the pickaxe book :)
Great point. I'm accustomed to compilers that require all the source up front. That actually ties into #558 (debug support). One of the big challenges is what to do when CoffeeScript code calls buggy code from a precompiled CoffeeScript file. Since the compiler doesn't have access to the original CoffeeScript, the compiler can't show the original line of code responsible for the error (without an intermediary form like a source map).