javascript - Unexpected token ILLEGAL error when lines of code are split -


i playing around source code of timesheet.js(see specific line) , came across small bug, see below line of code:

            '<span style="margin-left: ' + bubble.getstartoffset() + 'px; width: '              + bubble.getwidth() + 'px; " class="bubble bubble-' + (cur.type || 'default' ) +  '"></span>', 

when generate html , split in 2 lines works fine, if following i.e. split html in 3 lines , so:

            '<span style="margin-left: ' + bubble.getstartoffset() + 'px; width: '              + bubble.getwidth() + 'px; "              class="bubble bubble-' + (cur.type || 'default' ) +  '"></span>', 

i following error:

uncaught syntaxerror: unexpected token illegal

why ? why when spit code multiple lines error occur ? can explain ? question.

thank you.

alex-z.

well, duh, split code in middle of string literal. can't split anywhere want - there's rules language. it's if split in middle of getstartoffset gets on 1 line, , tartoffset on - it's plain wrong.

the original split in expression - note how second line starts +, , isn't in string literal.

a correct split this:

'<span style="margin-left: ' + bubble.getstartoffset() + 'px; width: '  + bubble.getwidth() + 'px; " class="bubble bubble-'  + (cur.type || 'default' ) +  '"></span>', 

if need split in middle of string literal, need end , append another:

'<span style="margin-left: ' + bubble.getstartoffset() + 'px; width: '  + bubble.getwidth() + 'px; " ' + 'class="bubble bubble-' + (cur.type || 'default' ) +  '"></span>', 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -