please add x .= f()

Bergi a.d.bergi at web.de
Tue Aug 11 02:27:27 UTC 2015


Isiah Meadows schrieb:
> That's not really the point.
>
> The suggestion is this instead:
>
> ```js
> if (s[0] === '/') s = s.slice(1);
> if (s[0] === '/') s .= slice(1);
> ```
>
> This already exists in CoffeeScript and most derivatives/dialects.
>
> ```coffee
> s .= slice 1 if s[0] is '/'
> ```
>
> Don't know of any other languages that have an equivalent, though.

Really? Which version of CS, or which dialect are you using? It doesn't 
work for me in the online tool 
<http://coffeescript.org/#try:s%20%3D%20%22%2Fsomething%22%0As%20.%3D%20slice%201%20if%20s%5B0%5D%20is%20'%2F'>.

But if you're that much inclined to save single characters, I'd 
recommend to use
```js
s = s.slice(s[0] == '/');
```

  Bergi


More information about the es-discuss mailing list