satyr / coco

Unfancy CoffeeScript
http://satyr.github.com/coco/
MIT License
497 stars 48 forks source link

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

Closed demark closed 11 years ago

demark commented 12 years ago

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, '_'
                                .to-upper-case!

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.

satyr commented 12 years ago

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

demark commented 12 years ago

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?

satyr commented 12 years ago

only to ordinary variables

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

this overhead will only cause on preprocess

Right.

satyr commented 11 years ago

Whipped up a trial impl there. Some notes:

satyr commented 11 years ago

Merged as is.