代码之家  ›  专栏  ›  技术社区  ›  Geuis

在我的项目中添加sizzle js会破坏项目

  •  3
  • Geuis  · 技术社区  · 15 年前

    我不太清楚这里发生了什么。我的代码如下:

    var mycode = {
        init:function(){
            //my code here
        }
    }
    
    //sizzle pasted here...
    (function(){ //sizzle code here })();
    

    其中“sizzle code here”是sizzle的全部复制/粘贴。sizzle包含在一个匿名函数中,所以我不确定干扰是什么。

    一旦我以这种方式添加sizzle,我在“mycode”对象文本中的JS就停止工作,并且我会得到类似“mycode未定义”这样的错误。这发生在Mac版的Chrome、Firefox 3.5.x和Safari 4 Mac上。

    2 回复  |  直到 14 年前
        1
  •  1
  •   Livingston Samuel    14 年前

    代码应该是

       var mycode = {
            init:function(){
                //my code here
            }
       };
    
        //sizzle pasted here...
       (function(){ /*sizzle code here*/ })();
    

    “mycode”对象后缺少的分号结果为,

    var mycode = { init:function() {}}(function(){/*sizzle code here*/ })();
    

    从而导致错误;)

        2
  •  0
  •   jjacka    15 年前

    缺少函数包装的结束paren,应为:

    (function(){ //sizzle code here })();