Skip to content

Workaround for missing ES6 feature: default values for function parameters (combined with object destructuring) #4509

Answered by tonygermano
tom08zehn asked this question in Q&A
Discussion options

You must be logged in to vote

The only way to fix unsupported syntax would be to fix it in Rhino itself. The maintainers are happy to accept PRs for missing functionality.

This is not as elegant, but javascript existed for a long time without destructuring assignments and function parameters with defaults. Your function here:

function foo(bar, {baz}={}) {
    console.log(bar); // to be replaced by logger.debug(bar) in Mirth
    console.log(baz);
}

Becomes the following when transpiled by Babel if you want to use the same calling syntax:

function foo(bar) {
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
      baz = _ref.baz;
  logger.debug(bar);
  logger.debug(baz);
}

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@tonygermano
Comment options

@tom08zehn
Comment options

Answer selected by tom08zehn
Comment options

You must be logged in to vote
1 reply
@tonygermano
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants