gpt4 book ai didi

javascript - 防止 Meteor 将脚本包装在立即调用的函数表达式中

转载 作者:行者123 更新时间:2023-11-29 19:23:10 25 4
gpt4 key购买 nike

Meteor 将在任何 JS 文件的内容周围包装一个立即调用的函数表达式 (IFFE),以确保文件之间没有命名空间冲突。

我正处于一个使用 beta npm 模块的项目的早期阶段。我希望能够直接从具有全局范围的浏览器控制台运行代码。

有没有办法很好地要求 Meteor 不要将我所有的脚本包装在 IFFE 中,这样我就可以创建全局函数和访问全局变量,从而更容易地理解 beta npm 模块在做什么(以及它是什么做错了)?

提前致谢。

最佳答案

如果您的代码在客户端运行,您只需将其放入client/compatibility 文件夹即可。来自 meteor 文档(http://docs.meteor.com/#/full/structuringyourapp):

client/compatibility

This folder is for compatibility JavaScript libraries that rely on variables declared with var at the top level being exported as globals. Files in this directory are executed without being wrapped in a new variable scope. These files are executed before other client-side JavaScript files.

关于javascript - 防止 Meteor 将脚本包装在立即调用的函数表达式中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32166015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com