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

Can someone explain the 'same name key:value shortcut' feature?


It's a DRY thing. Often in JS, object literals assign their keys to values of the same name -- you'll see a lot of this:

    $.ajax(url, {
      data: data,
      contentType: contentType,
      success: success,
      error: error
    });
... not so nice. So as a first stab, you can clean it up like so:

    $.ajax url, {data, contentType, success, error}
... but it's especially nice in the context of destructuring assignment, like for your Node.js imports, for example.

    {spawn, exec} = require 'child_process'


Nice. Thanks Jeremy.




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

Search: