In the book Google Script by James Ferreira, isbn 978-1-449-31852-9, on page 41 Final code for the hand coded style, the first line shows:
button.addClickHandler(validateEmail)
AND this is the ONLY statement line that does not end with a semi-colon terminator.
My question is Why?
I have tried adding a semi-colon terminator but then the code fails.
Could you explain why we do not put a semi colon terminator and what this means?
Thanks,
Nick
nick.morter@gmail.com
-
Hi, Nick.
I'm going to forward your question to the author to see if I can get this answered for you.
Best,
Daniel R.
O'Reilly Media Customer Service Team -
-
Hi Nick, thank you for purchasing my book.
Have a look at the next line in the code:
.addCallbackElement(mainPanel);
The period at the begging tells us that this is a continuation of the statement. By putting a semicolon at the end you break the statement.
The reason you will see this in code is to make it more readable by fitting it all into one window or simply to provide some organization. JavaScript will ignore the white space between the code fragments.
Happy coding,
James -
-
Hello James,
In my version of the book, this is what I see at the top of page 41:
button.addClickHandler(validateEmail)
//handler
var handler = app.createServerHandler('contactMe')
.validateEmail(email)
.addCallbackElement(mainPanel); button.addClickHandler(handler);
---------------------------------------------------------------------------------------------
The next statement is therefore:
var handler = app.createServerHandler('contactMe')
.validateEmail(email)
.addCallbackElement(mainPanel); button.addClickHandler(handler);
and there is no semi-colon terminator after
button.addClickHandler(validateEmail)
So in the code I tried out there was no semi-colon after:
button.addClickHandler(validateEmail)
Regards,
Nick -
-
ok I see where you are. Yes you can add a semi-colon there. JS is not very picky about this.
-