防止Meteor包裹在立即调用的函数表达式中的脚本 [英] Prevent Meteor from wrapping scripts in an immediately-invoked function expression

查看:116
本文介绍了防止Meteor包裹在立即调用的函数表达式中的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

在使用beta npm模块的项目的早期阶段。我想能够从浏览器控制台直接运行代码,它具有全局范围。

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.

有一种方法可以让Meteor很好地不打包我所有的脚本一个IFFE,以便我可以创建全局函数和访问全局变量,因此更容易理解beta npm模块正在做什么(以及它做什么错误)?

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)?

提前感谢。

推荐答案

如果你的代码在客户端运行,你可以简单地把它放入客户端/兼容性文件夹。从流星文档( http://docs.meteor.com/#/full/structuringyourapp):

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):


客户/兼容性

这个文件夹是为了兼容性的JavaScript库依赖
变量声明的顶级的var被导出为
全局变量。此目录中的文件被执行,而不被包装在
新的变量作用域中。这些文件在其他
客户端JavaScript文件之前执行。

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.

这篇关于防止Meteor包裹在立即调用的函数表达式中的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆