Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upSemicolon and self executing anonymous functions #516
Comments
This comment has been minimized.
This comment has been minimized.
|
You probably want to do: ;(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0]
if (d.getElementById(id)) return
js = d.createElement(s); js.id = id
js.src = '//connect.facebook.net/en_US/sdk.js'
fjs.parentNode.insertBefore(js, fjs)
}(document, 'script', 'facebook-jssdk'))
|
This comment has been minimized.
This comment has been minimized.
|
Oh, thanks for your fast reply! It's working like you say. Could you give me a brief explanation on why it's working? Cheers! |
This comment has been minimized.
This comment has been minimized.
|
@Uxio0 my 2 second explanation: var foo = function foo (z) { return z }
(9)
console.log(foo)
// => 9Compared to var foo = function foo (z) { return z }
;(9)
console.log(foo)
// => [Function: foo] |
This comment has been minimized.
This comment has been minimized.
|
Awesome @dcousens and @yoshuawuyts, thank you very much! |
dcousens
added
the
question
label
May 10, 2016
dcousens
closed this
May 10, 2016
lock
bot
locked as resolved and limited conversation to collaborators
May 10, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Uxio0 commentedMay 10, 2016
Standard format is breaking my code removing the semicolons.
You just have to take Facebook SDK Api Example:
It works. Notice that if you remove the semicolon on }; you get an error FB is not defined.
When it's formatted to standard-format, it's not working anymore (FB not defined):
Maybe I'm doing something wrong.