Giter Club home page Giter Club logo

Comments (5)

jashkenas avatar jashkenas commented on July 23, 2024

Using the latest CoffeeScript, this compiles just fine (despite looking like a mess) -- of course, you have to indent it correctly:

$('a').each(
  =>
    $(this).css()
    $(this).css()
    $(this).css()
).map(
  => $(this).attr('href')
).end()

Compiles into:

$('a').each(function() {
  $(this).css();
  $(this).css();
  return $(this).css();
}).map(function() {
  return $(this).attr('href');
}).end();

Closing the ticket...

from coffeescript.

weepy avatar weepy commented on July 23, 2024

Ah so you can't use the () in this case

$('a').each()
  =>
    $(this).css()
    $(this).css()
    $(this).css()
.map() => $(this).attr('href')

=> syntax error fail

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

Yeah, absolutely -- if you want to chain off a function, you'll have to enclose the call with parenthesis. I don't really think that your example should be able to compile. Chaining, block syntax, and significant whitespace don't mix too well. If it could, we could end up with ambiguous looking things like this:

els.each() el =>
  funcs.each() func =>
    func.properties.select() prop =>
      prop.isActive
  .reverse()

Notice how that reverse is two blocks back.

from coffeescript.

weepy avatar weepy commented on July 23, 2024

right, so is it correct that because of the way whitespace works differently to python, you can only close one block per line?

from coffeescript.

jashkenas avatar jashkenas commented on July 23, 2024

No, you can close as many as you'd like.

I just think that allowing the above example to compile is asking for trouble. If you're going to call a method on something, just visually speaking, you need to attach that period to the thing that you're calling, not just a level of indentation. Looking at the example, I would have a hard time figuring out what's being reversed.

from coffeescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.