Access to exported functions line by line in ES6 modules

Consider the following:

exports['handleEvent']('event');

export function handleEvent(event) {
  // do something with `event`
}

This works when using babel to forward node modules, because it imposes everything on the export object. Is there any export facility concept in vanilla ES6? I want to be able to call a method using the string of its name.

One thing that I was thinking about is simply sticking to all the functions on the object and exporting them individually. Another option is to use some evil things. Are there standard methods for accessing an ES6 export in the current module line by line?

+4
source share
1 answer

Not quite sure what I am following ...

ES6. , ?

1

:

export function one() { return 1 };
export function two() { return 2 };

:

import {one, two} from 'producer';

one();
two();

2

:

export function one() { return 1 };
export function two() { return 2 };

:

import * as producer from 'producer';

producer.one(); // or producer['one']()
producer.two();

3

:

export default {
  one() { return 1 },
  two() { return 2 }
};

:

import producer from 'producer';

producer.one(); // or producer['one']()
producer.two();

4

:

export default {
  one() { return 1 },
  two() { return 2 }
};

:

import {one, two} from 'producer';

one();
two();

5

:

export default function() { return 1 };
export function two() { return 2 };

:

import one, {two} from 'producer';

one();
two();
+1

All Articles