Coder Social home page Coder Social logo

Comments (5)

vzakharov avatar vzakharov commented on June 1, 2024

After reading this, I kind of get why CS doesn’t have let, but my question is more about solving a practical issue rather than syntax.

If, for example, I loop through all the properties of an object and want to create something for each property (say, a watcher), I need to be able to refer to that thing that this something was created for. And currently I don’t really see how this is achievable with CS.

from coffeescript.

vzakharov avatar vzakharov commented on June 1, 2024

Found out that I can do it with [].forEach:
image

Weird, but I’ll try to get used to it...

from coffeescript.

vzakharov avatar vzakharov commented on June 1, 2024

Still keeping it open to get an expert answer on whether my solution is the “ideologically correct” one.

from coffeescript.

edemaine avatar edemaine commented on June 1, 2024

The standard CoffeeScript solution is:

for key in keys
  do (key) =>
    funcs[key] = => key

I think it'd be great to add the shorthand for let key in keys for this common case, though.

from coffeescript.

GeoffreyBooth avatar GeoffreyBooth commented on June 1, 2024

Yes, do is the idiomatic way to create a new scope (like you’re wishing you could have the for loop do, which it does for let/const variables). And since [].forEach takes a callback function, within that callback is a new function scope just like do creates, so that’s also a fine solution and perhaps simpler to understand.

Closing as there has been lots of discussion of let/const elsewhere and I don’t see it getting revisited anytime soon. If we design a way to “opt in” to block-scoped variables, a proposal to do so should get its own thread and also not cause any breaking changes.

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.