Subtract code from app.js

江枫思渺然 提交于 2019-12-11 02:37:09

问题


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.

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 I'm using Ember CLI


回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/24699942/subtract-code-from-app-js

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