如何導出這個覆蓋函數,以便導入模塊可以檢查函數是否被調用?ES6導出覆蓋函數
// util.js
export function isPageload() {
return (!!(isPageload = function() { return false; }));
}
當我編譯與巴貝爾,我得到這個錯誤:
Uncaught TypeError: (0 , _util2.default) is not a function
這裏是ES5相當於:
var isPageload = function() {
return (!!(isPageload = function() { return false; }));
}
console.log(isPageload()); // true
console.log(isPageload()); // false
'let loaded = false;'then'loaded = true;'在函數體中。 – zerkms
更有針對性,爲什麼你會寫這個?爲什麼在導出時需要相同的函數名稱? –
@ Mike'Pomax'Kamermans當前語法會將導出更新爲返回false而不是原始函數的函數,就像ES5版本一樣。 – loganfsmyth