从app.js中减去代码 [英] Subtract code from app.js

查看:67
本文介绍了从app.js中减去代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了解决一些与触摸相关的问题,我在app.js中编写了一个脚本,重新打开并增强了EventDispatcher。脚本很长,污染了通常这么干净的app.js。

To tackle some touch-related problems I have written a script in app.js to reopen and enhance the EventDispatcher. The script is pretty long and contaminates the normally so clean app.js.

所以我想把我的脚本放在一个单独的文件中,而不是以某种方式导入应用程序.js文件。你认为这是最好的(最干净的)方法吗?

So I'd like to have my script in a seperate file and than somehow be imported in app.js. What in your opinion is the best (cleanest) way to do this?

FYI我使用Ember CLI

FYI I'm using Ember CLI

推荐答案

我将脚本放在 public / assets / js 中,并使用 Modernizr.load (Modernizr执行是的,不要),如这里内的脚本标签就在你的标签结束标签之前.html 文件。在这种情况下,您可以使用 Modernizr.touch 来检测用户设备上的触摸事件支持,如果存在,则加载touch polyfill / script。

I would place the script in file in in public/assets/js and load the script using Modernizr.load (Modernizr's implementation of yes nope) like this inside of script tags just before the closing body tag of your index.html file. In this situation, you could use Modernizr.touch to detect for touch event support on the user's device and, if present, load the touch polyfill/script.

或者,将文件放在同一个地方,并使用初始化程序中的 $。getScript(url)在if语句中加载脚本或应用程序视图。

Alternatively, place the file in the same place and load the script inside an if statement using $.getScript(url) in an initializer or the application view.

在这两种情况下,脚本将不会导入 app.js ,但仍将加载并运行。

In both situations the script will not be imported into app.js but will still be loaded and ran.

这篇关于从app.js中减去代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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