3 ms·
I suspect the vote yo-yoing may be to do with dismissing the possible value of declaring functions inside functions - on a website run by a company called Y Com
by jameshart 13y ago
I suspect the vote yo-yoing may be to do with dismissing the possible value of declaring functions inside functions - on a website run by a company called Y Combinator.
I think the difference here is that you see
function Foo() {
...
}
as a 'normal' function declaration. I see it as a syntax which hides the truth - that that is actually putting
var Foo = function Foo() {
..
};
at the top of its scope. It's a special syntax for the special case of "I want this function to have this name and be bound to a variable with the same name for the whole of its enclosing scope". But JavaScript permits me to do lots of OTHER things with functions, and pretending it can't doesn't help me write better JavaScript code.
functions are the ONLY way in JavaScript to restrict the scope of a name. How can you talk about the risks of moving things if you aren't even taking advantage of JavaScript's only mechanism to create safely encapsulated name scopes?
- mattmanser 13y agoWhen did I say I didn't use the convention for namespaces? I'm talking about simple code structure. You need a function. Do you put it in a var or not. I have nothing against closures or namespaces or object declaration or many of the million other things you can twist objects in js to do. What I hate is this: var checkValid = function(item) { return item!= blah; } When it should be: function checkValid(item) { //blah } Stop accusing me of a position you've made up in your head.