[Feature request] Add . (dot) or other symbol(s) as variable reference in assignment block #180

demark opened this Issue Oct 17, 2012 · 5 comments

2 participants


Currently we have this sugar: some.long.long.long.variable .= to-upper-case!

But we often have a lot of functions from some libs that takes var as argument and returns new value.

I suggest to add . (dot) as variable reference in the assignment block:

some.long.long.long.variable = '<b>hello</b> world!'

some-external-lib.sanitize = (s) -> s.replace /<\/?[^>]+>/g, ''

some.long.long.long.variable =  some-external-lib.sanitize .
                                .replace /\s+/g, '_'

And we can use some.long.long.long.variable = . .to-upper-case!

Maybe instead of dot use &. or $& (like in regex)

I think this will be very usable.


I've considered this feature, but been dismissing it due to:

  • difficulty wrt destructuring, e.g.: [a, b] = f(.).
  • the overhead (extra traversing of RHS on each assignment) it would add.
@demark demark closed this Oct 17, 2012
@demark demark reopened this Oct 17, 2012

So, what if strict assignment with reference only to ordinary variables (e.g. a = ..., b = ...)
Second, afaik this overhead will only cause on preprocess. In js-output there only need to replace reference symbols. Am i right?


only to ordinary variables

Yup, we'd have to disallow it on destructuring LHS.

this overhead will only cause on preprocess



Whipped up a trial impl there. Some notes:

  • Simbol is <>. Standalone . as proposed is too iffy.
  • Does not cross-scope. E.g. f = -> <> is syntax error.
  • Turns out destructuring is naturally prohibited because RHS is evaluated first and gets stray error.

Merged as is.

@satyr satyr closed this Feb 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment