maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
728 stars 58 forks source link

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

Open zapu opened 7 years ago

zapu commented 7 years ago
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);
    }
maxtaco commented 7 years ago

didn't even know you can do that.

zapu commented 7 years ago

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