Reputation: 157981
Say you have this ES6 module:
// ./foobar.js
export default function(txt)
{
// Do something with txt
return txt;
}
Is it possible to add another function export to the same file, that uses this default function? I assume it's possible, but how do you call it?
// ./foobar.js
export default function(txt)
{
// Do something with txt
return txt;
}
export function doSomethingMore(txt)
{
txt = // ? how to call default function ?
// Do something more with txt
return txt;
}
Upvotes: 1
Views: 82
Reputation: 2302
Try exporting a reference to the function:
var theFunc = function(txt)
{
// Do something with txt
return txt;
}
export default theFunc
Then you can reference theFunc
elsewhere.
Upvotes: 1
Reputation: 5986
you can either create the function then export it or just name the function
export default function myDefault () {
// code
}
export function doSomething () {
myDefault()
}
or
function myDefault () {
}
export function doSomething () {
myDefault()
}
export default myDefault
Upvotes: 2
Reputation: 224855
You can give it a name, and it’ll be in scope:
export default function foo(txt) {
// Do something with txt
return txt;
}
export function bar(txt) {
txt = foo(txt);
return txt;
}
Upvotes: 3