Prevent Meteor from wrapping scripts in an immediately-invoked function expression

 ̄綄美尐妖づ 提交于 2019-12-11 02:59:06

问题


Meteor will wrap an immediately-invoked function expression (IFFE) around the contents of any JS file, to ensure that there are no namespace conflicts between files.

I am at the very early stage of a project which uses a beta npm module. I would like to be able to run code directly from the browser console, which has global scope.

Is there a way to ask Meteor nicely not to wrap all my scripts in an IFFE, so that I can create global functions and access global variables, and so understand more easily what the beta npm module is doing (and what it is doing wrong)?

Thanks in advance.


回答1:


If your code is running on the client side, you can simply put it into the client/compatibility folder. From the meteor docs (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.



来源:https://stackoverflow.com/questions/32166015/prevent-meteor-from-wrapping-scripts-in-an-immediately-invoked-function-expressi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!