3

My page is throwing a javascript error, but I can't figure out why. I'm trying to debug a script that was imported to my client's site. It's throwing the error here:

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

The error is "Uncaught SyntaxError: Unexpected token ("

For context, here is the chunk of code it is located in. Unfortunately I don't really know what purpose these functions serve, but the error is preventing the page from loading correctly. Hopefully this Javascript is enough to give the context, the full script is very long.

_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
}

If you want to look at the page, it's located here

2
  • 1
    just a suggestion- you can put your script on jsFiddle and click on JSHint, it highlights all the syntax errors Commented Aug 17, 2015 at 20:09
  • Or you could just put your code in JSHint. Commented Aug 18, 2015 at 1:53

1 Answer 1

5

Every section of your code that looks like:

            return

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

is broken. The rules of JavaScript automatic semicolon insertion are such that those return statements are treated as complete when the parser hits the newline. It has to look like:

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

That may seem astonishing, but it's true. The error you're getting happens because the parser thinks that that function keyword is opening a new function declaration statement, and in such a statement the function name is not optional.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.