'missing ) in parenthetical

I keep getting that my javascript is missing ) in parenthetical [Break On This Error] if ( (this.scrollTop < this.scrollH...uches[0].pageY > scrollStartPosY+5) )

function touchScroll(id){
    if(isTouchDevice()){ //if touch events exist...
        var el=document.getElementById(id);
        var scrollStartPosY=0;
        var scrollStartPosX=0;

        document.getElementById(id).addEventListener("touchstart", function(event) {
            scrollStartPosY=this.scrollTop+event.touches[0].pageY;
            scrollStartPosX=this.scrollLeft+event.touches[0].pageX;
            //event.preventDefault(); // Keep this remarked so you can click on buttons and links in the div
        },false);

        document.getElementById(id).addEventListener("touchmove", function(event) {
            // These if statements allow the full page to scroll (not just the div) if they are
            // at the top of the div scroll or the bottom of the div scroll
            // The -5 and +5 below are in case they are trying to scroll the page sideways
            // but their finger moves a few pixels down or up.  The event.preventDefault() function
            // will not be called in that case so that the whole page can scroll.
            if ( (this.scrollTop < this.scrollHeight-this.offsetHeight) && (this.scrollTop+event.touches[0].pageY < scrollStartPosY-5) || (this.scrollTop != 0 && this.scrollTop+event.touches[0].pageY > scrollStartPosY+5) )
                    event.preventDefault(); 
            if ((this.scrollLeft < this.scrollWidth-this.offsetWidth && this.scrollLeft+event.touches[0].pageX < scrollStartPosX-5) || (this.scrollLeft != 0 && this.scrollLeft+event.touches[0].pageX > scrollStartPosX+5))
                    event.preventDefault(); 
            this.scrollTop=scrollStartPosY-event.touches[0].pageY;
            this.scrollLeft=scrollStartPosX-event.touches[0].pageX;
        },false);
    }
}

And I cannot for the life of me figure out why.



Solution 1:[1]

For me it was + missing in some string concatenation that happened inside ().

Solution 2:[2]

It seems according to JSLint that this script is fine, except for some type conversions, that aren't mandatory to follow. It must be something before this that leaves an open parenthesis.

Solution 3:[3]

Do you have code before what you are showing above? You may have an unclosed paren before this function that javascript is only realizing is unclosed when it gets to this.

Solution 4:[4]

In my case, I wasn't thinking, and I was:

  • pasting typescript into the browser console

Solution 5:[5]

In my case I solved the issue by rebuilding modules cache (I used https://github.com/mzgoddard/hard-source-webpack-plugin )

Solution 6:[6]

In my case: using typescript inside a function that was written as a string value, in the new $accumulator operator in MongoDB (see the parameter of 'accumulate' below):

const aggregationPipeline: object[] = [
  {
    $group: {
      _id: 1,
      Data: {
        $accumulator: {

          init: `function() {        // Set the initial state
              return {};
            }`,

          initArgs: [],        // Argument to pass to the init function

          accumulate: `function(state: any) {  // Define how to update the state
              return state;
            }`,

          accumulateArgs: [],                     // Argument required by the accumulate function

          merge: `function(state1, state2) {
              return state2;
            }`,

          finalize: `function(state) {                   // Adjust the state to only return field we need
              return state;
            }`,

          lang: "js"
        }
      },
    }
  },
];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 przemo_li
Solution 2 zatatatata
Solution 3 Mike C
Solution 4 jmunsch
Solution 5 gorodezkiy
Solution 6 xxx