我编写了一个服务器端实用程序,用于管理javascript页面依赖项。在开发过程中,它将javascript作为单独的文件提供(按照定义的顺序嵌入单个脚本标记),并在生产模式下读取文件,缩小它们(仅限空白空间中的Google Closure),并通过单个脚本标记嵌入它们。
目前,我已经关闭了缩小以消除该变量......所以它所做的只是将文件连接在一起,并在每个文件之间换行。
当我进入生产模式时,我会在许多嵌入的文件中出现虚假问题。
那么,是否有人对通过将一组文件作为单个连接文件提供可能导致的问题有任何想法?我很茫然。
对于那些想要更多细节的人:
我确定订单是正确的。
对于此示例,有问题的文件列表相当大,但包括jquery,angular,controllers,jquery dnd fileupload,controller等。
我在组合的这一行得到“Uncaught Type Error:undefined is not function”:
(function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};})(jQuery);
跟随生成全局变量的其他一些文件嵌入:
var FocusElementDirective = function() {
...
}
var DirectiveApplier = function(){
...
}
var AgeCalculator = function(){
...
}
另一个:当我在jquery fileupload的angular插件中触发“add”事件时,它会给出Uncaught TypeError:Object#没有方法'scope'。它指向的行在jquery fileupload angular模块中(版本9.0.5的第89行):
add: function (e, data) {
if (e.isDefaultPrevented()) {
return false;
}
var scope = data.scope(), // this line
答案 0 :(得分:1)
刚刚发生这件事,首先想到的是它可能与全局变量有关,Crockford抱怨这是javascript的弱点之一。
快速说明:
JavaScript global variables & self-invoking anonymous functions
就在我头顶。
答案 1 :(得分:1)
所以,我找到了它,结果证明这是一件非常简单的事情......这么简单,我把头发拉了几个小时寻找技术:
我有一份副本。
当作为标签加载时,浏览器只会加载文件一次。连接时,代码实际上是重复的。这导致了各种各样的怪异(例如,事件处理程序被迷上了错误的版本)。
来自编译语言背景,我有点期待一些重复的符号类型的通知......动态语言啊。