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 upShould function declaration in catch be allowed? #131
Comments
dcousens
added
the
question
label
May 12, 2015
This comment has been minimized.
This comment has been minimized.
julien-f
commented
May 12, 2015
|
Function declarations are hoisted (automatically moved to the top of the scope) so your What you want is to use a function expression assigned to a variable: initialise()
function initialise () {
try {
return nativeImplementation()
} catch (e) {
var fakeImplementation = function () {
// ...
}
return fakeImplementation()
}
} |
This comment has been minimized.
This comment has been minimized.
|
What @julien-f said is correct. The error message could be more helpful, but I think we should keep this rule in place. I'm going to close this issue. Feel free to continue discussing if you want. |
feross
closed this
May 13, 2015
lock
bot
locked as resolved and limited conversation to collaborators
May 11, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
davidpfahler commentedMay 10, 2015
I got
Move function declaration to function body root.error for the following code:I was intentionally declaring the
fakeImplementationfunction in the catch block, because I though it to be a waste to declare the function if it is most likely never being used. Isn't this an anti-pattern?