I'm receiving that kind of error, I can't copy the whole code (quite big), but I can find a reason why that happens.
In this portion of code
'... })})(jQInteractives);</script></textarea>')
} else if (ide == "feverchart") {
$("#codeArea").append('<textarea>'+
'<style>.stretch:after {content: ....
I'm using ... just to indicate the code follows there, but it's not a problem of what's around it, even if I move it, the problem always appears to be in the line
$("#codeArea").append('<textarea>'+
It has nothing to do with the '+ because I've tried without it and just continuing the line.
I'm using the exact same line in other parts of the complete code without problems, and I don't see the problem here either.
Any clues?
Per comment, I moved it to a different place, to avoid problems with not properly closing smoething. I have the same problem when I move it here:
if (ide == "blanktemp") {
} else if (ide == "feverchart") {
$("#codeArea").append('<textarea>'+
'<style>.stretch:after {content: ".";display: [... code continues ...]
It's always the same line, no matter where I put it.
Related
I am getting some really weird syntax errors [Uncaught SyntaxError: Unexpected identifier] for seemingly normal code.
Getting an error if I write anything after the 1st line in the else block..
if (classlist.length == 0) {
lastClickCatID = -1;
}
else {
lastClickCatID = +classlist.value.split('-')[1];
// **Getting error if I write anything here, even for comments like this**
}
Getting the error if I just use two words in the comment (with a space between them). And of course getting error for any JS statements, even basic console logs.
Also, getting an error for a console.log line in the following code which has been commented out (the 4th line: console.log-"UNDO"):
// Push this data into the undo array
undo.push([lastClickDivID, lastClickCol, lastClickRow, lastClickCatID, nextClickCatID]);
//console.log("UNDO", undo[0][0], undo[0][1], undo[0][2], undo[0][3], undo[0][4]); // *Getting error if I include this line*
console.log(undo.pop());
Getting an error with or without the comment tag. But if I remove the entire line, it works fine.
I have another line:
nextClickCatID = +id2;
Again getting errors for doing a console.log of the variable. But it works fine if I remove the '+' and just use next 'nextClickCatID = id2; '.
Also getting many other weird errors like that within this function (it will get too long if I include them). Any idea why I am getting errors like these for seemingly normal code?
I have solved it. It strangely worked when I removed the space between the () and the curly brackets in the jquery document ready function. Changed from...
$(function() {
to:
$(function(){ // with no space between the parentheses and the curly brackets
I want to add that - it was working fine before with the same structure (with space in between brackets) all this while. But suddenly decided to give an error today in a particular function. If somebody can clarify why this happened, it will still be very relevant.
I'm wondering how the sequence shown below could possibly occur.
Here is the function in question:
WebSocketConnector.prototype.sendMessage = function(message) {
if (socket !== null) {
socket.send(message);
console.log('Sent: ' + message);
} else {
alert('Failed to send message. WebSocket connection not established.');
}
};
And here is what happens when I debug a call to this function:
1. Start at line 32.
2. Step In, advances to line 33.
3. Step In again, advances to line 34.
4. Step in one more time, advances to line 36???
--> How can control possibly go directly from the last line of the if block to the first line of the else block?
Some important facts:
There are no missing steps here.
This really happened.
I'm only calling sendMessage from one place, and I'm logging when that call occurs. There are no unaccounted for sendMessage calls in the log, so I don't believe asynchrony is an explanation.
I also tried the same thing with the Firebug debugger and the same crazy thing happens.
Edit/Followup
If I add a console.log statement to the first line of the else block (pushing the alert down to line 37), the control will go right from line 34 to line 37 (skipping the console.log statement).
Also, I should have mentioned, no alert actually ever appears, even when stepping directly into that code.
Edit 2
Here is the spacing and CRLF's of the sendMessage function:
This is because the debugger steps to the last executable line before returning to the calling stack frame. In your case this is line 36 containing the alert() function. It would be clearer if the debugger jumped to the closing curly brace of the function, i.e. line 38.
There is already a report to change this behavior:
https://bugzil.la/1013219
Unfortunately there are some really odd behaviors with the debugger in Firefox. I wouldn't be surprised if what you describe might be related to this bug. The "step" functionality sometimes doesn't do what you would expect, or what Chromium browser does.
By mistake, an URL was pasted into a JavaScript snippet. Reduced to a minimum, it looked roughly like this:
function(){
/* a bunch of code */
http://www.stackoverflow.com
/* a bunch of code */
return "it still works";
}
It was overlooked for quite some time, because it did not produce an error. Why is that? Why does this function still run without erroring?
You're defining a label called http. The // in the url comments the rest out.
see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label
Before returning a string value of it still works it is creating a label http: note the usage of :. And the remaining part of the code is commented out using the Single Line comment: //
There wasn't any sort of error in your code, because there was no Syntax error in your code. That's why it worked correctly.
I have a function that is parsing xml which contains javascript function calls. An example of this is:
eval(getElementText(PropValue[0]));
getElementText(PropValue[0] = top.hidePopWin()
I have followed this call up to the hidePopWin function and watched it complete from the top of the function to the bottom of the function.
Everything looks in order however I get this pesky error in Firefox: top is null
As you have probably guessed hidePopWin closes the popup window that is currently displayed.
So, hidePopWin is called and it goes through just fine (in fact the popup does in fact close), but after that is the problem. It doesn't go to the next step. I get the top is null message in Firefox (firebug) and it just stops.
The only other thing I need to mention is that this whole process starts on a double click event (legacy code). There is also a single click event that fires as well. At first I thought maybe that was the issue, however, I took out the reference to the onclick event and I still get the same message.
So I'm thinking that it has something to do with the eval statement. Just for more information I am placing a console.log("1") above the eval statement and a console.log("2") below the eval. The "1" prints, the "2" does not.
Does anyone have any ideas as to what might be the issue?
Update:
if(getElementText(PropValue[0]) == "top.hidePopWin();"){
console.log('here');
top.hidePopWin();
console.log('end');
}else{
console.log(getElementText(PropValue[0]));
eval(getElementText(PropValue[0]));
}
OK I tried the above... I see the "here" statement, but it still says top is null. The "end" statement never prints. When I click on the top is null in FF it highlights the eval statement??? So I don't know what the heck is going on.
no, but could you change the code to directly execute the code outside eval and test?
So, change, eval(getElementText(PropValue[0]));
to
top.hidePopWin();
see if you get the same error.
is 'top' visible in that scope if you breakpoint in FF (on the console.log('here') line? It's sounding like there is no such variable (I don't know why the popup closes though).
OK... This may not be the best way to go, but I did finally get it to work. Per the suggestion to change the code to run top.hidePopWin(). I tried those suggestions however I was still getting the top is null issue.
In desperation I took out the "top." and now it works. So I'm guessing there was not a "top" variable (wierd notation in my opinion).
So now I'm capturing if the string is equaling "top.hidePopWin()" and then instead of calling the eval I'm just calling the function hidePopWin();
Seems to work. Let me know if there is another way of going about this.
This is my JavaScript (much stripped down):
function addContent() {
var content = [];
content.append(
makeVal({
value : 1
})
); // Generates lint message
}
Running a lint program over this, I get the message
unexpected end of line; it is ambiguous whether these lines are part of the same statement
on line 7. If I concatenate lines 6 and 7 the message goes away.
Can anyone explain where this ambiguity is? It seems to me that the parenthesis on line 7 is unambiguously closing the call to append().
It looks that way to me, too. Sounds like a bug in the lint program you're using.
You can understand why it would wonder, because the call to makeVal fits the profile of code that's relying on semicolon insertion — unless you look correctly at the wider context and realize it's within argument list for the append call. Seems to me the lint program is not actually parsing the language, just looking for patterns, which is going to mean it's going to have both false positives and false negatives.