How can I export this overwriting function so that an importing module can check whether the function has been called?
// util.js
export function isPageload() {
return (!!(isPageload = function() { return false; }));
}
When I compile that with Babel, I get this error:
Uncaught TypeError: (0 , _util2.default) is not a function
Here is the ES5 equivalent:
var isPageload = function() {
return (!!(isPageload = function() { return false; }));
}
console.log(isPageload()); // true
console.log(isPageload()); // false
The .default
in the error makes it clear that you are doing
import isPageload from 'foo';
when you probably want
import {isPageload} from 'foo';
since
export function isPageload() {
creates a named export, not a default export, and default export live-binding updating currently does not work in Babel.
Your approach to this problem does seem somewhat roundabout however. Why not do
let loaded = true;
export isPageLoaded(){
let state = loaded;
loaded = false;
return loaded;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With