How to export multiple functions as aliases in ES6

Viewed 456

I want to export multiple functions as aliases in ES6.

I exported it like this because I want to use export default but "as" doesn't seem to work.

const fn1 = () => {};
const fn2 = () => {};

export default = {
  fn1 as function1,
  fn2 as function2,
} // -> not working

How can I do what I want?

2 Answers

What follows export default should be an expression (not a =). So all you need to do after that is use the right syntax for a normal Javascript object:

export default {
  function1: fn1,
  function2: fn2,
};

I think that is a wrong syntax. Correct use would be without '=' before "{".

export default {
  fn1 as function1,
  fn2 as function2
}
Related