coffee-script icon indicating copy to clipboard operation
coffee-script copied to clipboard

iced3: Can't reference "@s" as "s" in code like `constructor : (@s) ->`

Open zapu opened this issue 8 years ago • 2 comments

michal@miso ~/iced_work » cat -n at_name.iced
     1	class Test
     2	    constructor : (@s) ->
     3	        console.log "s is ", s
     4	        console.log "@s is ", @s
     5	        console.log "@ is ", @
     6	
     7	new Test "hello world"
michal@miso ~/iced_work » iced at_name.iced
s is  hello world
@s is  hello world
@ is  Test { s: 'hello world' }
michal@miso ~/iced_work » iced3 at_name.iced
ReferenceError: s is not defined
  at new Test (/home/michal/iced_work/at_name.iced:3:30)
  at Object.<anonymous> (/home/michal/iced_work/at_name.iced:7:5)
  at Object.<anonymous> (/home/michal/iced_work/at_name.iced:1:1)
  at Module._compile (module.js:570:32)

Generated code has changed from: (on iced2):

function Test(s) {
      this.s = s;
      console.log("s is ", s);
      console.log("@s is ", this.s);
      console.log("@ is ", this);
    }

to (iced3):

function Test(s1) {
      this.s = s1;
      console.log("s is ", s);
      console.log("@s is ", this.s);
      console.log("@ is ", this);
    }

zapu avatar Jun 26 '17 17:06 zapu

didn't even know you can do that.

maxtaco avatar Jun 26 '17 17:06 maxtaco

me neither, looks like it's only working by accident in iced2 (and coffee as well?)

zapu avatar Jun 26 '17 17:06 zapu