Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Works in JS as well. Though I have never seen anyone put whitespace around field accesses like that, in any language.


Newlines are pretty common. Especially in chained cases. No?


i guess i forgot about the newlines case, and just had never seen anyone put spaces in like that without newlines, so figured it didn't exist. strange that it's even allowed.


That’s because C-like languages don’t distinguish newlines from other whitespace. If you want

  foo()
    .filter(...)
    .map(...)
then you have to allow

  foo() .filter(...) .map(...)
as well, as a matter of principle.


But this doesn't apply to Javascript in its absolute sense, since although

    (1) foo()
        .bar()
is equivalent to

    (2) foo() .bar()
there is a difference between

    (3) foo()
        bar()
and

    (4) foo() bar()
(the (3) results in valid code, whereas (4) would not).

But trying to argue that (2) should be syntactically invalid would be a very hard ask indeed.


Yes. Though even Python, which does treat newlines different from other whitespace, allows `object . someMethod` with spaces on either side.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: