我試圖更好地理解包含節(jié)點(diǎn)組件和其他 js 的 webpacked 包中的范圍。假設(shè)我的入口導(dǎo)入了八個(gè)要捆綁的文件: // entry point import './components/file1'; 導(dǎo)入'./components/file2'; ...導(dǎo)入'./components/file8';并假設(shè)在 file1.js 中我有:// file1.jslet bubbles = () => { console.log('likes cats');};// orfunction bubbles() { console.log('likes cats');}為什么那么,如果我在 files8 中有這個(gè)(最后導(dǎo)入),它會(huì)拋出一個(gè)未定義的錯(cuò)誤嗎?如何調(diào)用在其他導(dǎo)入中聲明的函數(shù)?// file8.jsbubbles(); // fails in any file other than file1.js where it's declared.
js 包和范圍混淆
ibeautiful
2021-11-12 15:54:25