2015-08-17 2 views
3

Моя страница бросает ошибку javascript, но я не могу понять, почему. Я пытаюсь отлаживать скрипт, который был импортирован на сайт моего клиента. Здесь выдается ошибка:Ошибка в Javascript: Неожиданный токен (

function(t){ 
    e._trigger("receive",t,this._uiHash(this)) 
} 

ошибка «Uncaught SyntaxError: Неожиданный маркер (».

Для контекста, вот кусок кода он расположен в К сожалению, я не знаю, с какой целью эти функции служат, но ошибка предотвращает загрузку страницы правильно. Надеюсь, этого Javascript достаточно, чтобы дать контекст, полный скрипт очень длинный.

_clear: function(e, t) { 
    this.reverting = !1; 
    var i, n = []; 
    if (!this._noFinalSort && this.currentItem.parent().length && this.placeholder 
     .before(this.currentItem), this._noFinalSort = null, this.helper[0] === 
     this.currentItem[0]) { 
     for (i in this._storedCSS) 
      ("auto" === this._storedCSS[i] || "static" === this._storedCSS[ 
       i]) && (this._storedCSS[i] = ""); 
     this.currentItem.css(this._storedCSS).removeClass(
      "ui-sortable-helper") 
    } else this.currentItem.show(); 
    for (this.fromOutside && !t && n.push(function(e) { 
      this._trigger("receive", e, this._uiHash(this.fromOutside)) 
     }), !this.fromOutside && this.domPosition.prev === this.currentItem 
     .prev().not(".ui-sortable-helper")[0] && this.domPosition.parent === 
     this.currentItem.parent()[0] || t || n.push(function(e) { 
      this._trigger("update", e, this._uiHash()) 
     }), this !== this.currentContainer && (t || (n.push(function(e) { 
      this._trigger("remove", e, this._uiHash()) 
     }), n.push(function(e) { 
      return 

      function(t) { 
       e._trigger("receive", t, this._uiHash(this)) 
      } 
     }.call(this, this.currentContainer)), n.push(function(e) { 
      return 

      function(t) { 
       e._trigger("update", t, this._uiHash(this)) 
      } 
     }.call(this, this.currentContainer)))), i = this.containers.length - 
     1; i >= 0; i--) t || n.push(function(e) { 
      return function(t) { 
       e._trigger("deactivate", t, this._uiHash(this)) 
      } 
     }.call(this, this.containers[i])), this.containers[i].containerCache 
     .over && (n.push(function(e) { 
       return 

       function(t) { 
        e._trigger("out", t, this._uiHash(this)) 
       } 
      }.call(this, this.containers[i])), this.containers[i].containerCache 
      .over = 0); 
    if (this.storedCursor && (this.document.find("body").css("cursor", this 
      .storedCursor), this.storedStylesheet.remove()), this._storedOpacity && 
     this.helper.css("opacity", this._storedOpacity), this._storedZIndex && 
     this.helper.css("zIndex", "auto" === this._storedZIndex ? "" : this 
      ._storedZIndex), this.dragging = !1, this.cancelHelperRemoval) { 
     if (!t) { 
      for (this._trigger("beforeStop", e, this._uiHash()), i = 0; n.length > 
       i; i++) n[i].call(this, e); 
      this._trigger("stop", e, this._uiHash()) 
     } 
     return this.fromOutside = !1, !1 
    } 
    if (t || this._trigger("beforeStop", e, this._uiHash()), this.placeholder[ 
      0].parentNode.removeChild(this.placeholder[0]), this.helper[0] !== 
     this.currentItem[0] && this.helper.remove(), this.helper = null, !t 
    ) { 
     for (i = 0; n.length > i; i++) n[i].call(this, e); 
     this._trigger("stop", e, this._uiHash()) 
    } 
    return this.fromOutside = !1, !0 
} 

Если вы хотите посмотреть на странице, он находится here

+1

всего лишь предложение - вы можете поместить свой скрипт на [jsFiddle] (http://jsfiddle.net/) и нажать на JSHint, он выделяет все синтаксические ошибки –

+0

Или вы могли бы просто поместить свой код в [JSHint] (http://jshint.com). – Xufox

ответ

5

Каждый раздел вашего кода, который выглядит следующим образом:

  return 

      function(t) { 
       e._trigger("out", t, this._uiHash(this)) 
      } 

сломана. Правила автоматической установки с запятой JavaScript таковы, что эти операторы return считаются полными, когда парсер попадает в новую строку. Он должен выглядеть так:

Это может показаться поразительным, но это правда. Ошибка, которую вы получаете, происходит потому, что парсер считает, что ключевое слово function открывает новый оператор объявления функции, и в таком выражении имя функции не является необязательным.

0: