简体   繁体   中英

How to export multiple functions as aliases in ES6

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?

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM