Douglas Crockford (JSON, JSLint, JSMin, Javascript: The Good Parts) is a founding father of modern Javascript. He is a frequent speaker on the Javascript circuit and, until recently, was the scheduled as the keynote speaker for the Nodevember Conference. For reasons no one can explain, he was removed from the conference schedule to help foster inclusivity. No one (including Crockford) knows why he was banned. Internet commenters have speculated it may have been due to a talk titled "Monads and Gonads" or slut shaming the "promiscuous" web or a his use of the gender (and species) exclusive phrase "hanging out there like a pair of dog balls". Others believe it's because he's a curmudgeon (aka grumpy old white cis heterosexual man). One of the Nodevember organizers (not involved with the decision to ban Crockford) has stepped down.
This is not the first time Crockford has experienced censorship -- he previously ported Maniac Mansion to the NES.
(Score: 1) by kurenai.tsubasa on Wednesday September 07 2016, @02:37AM
Ah, I see. Yeah, that's a helluva construct. Pretty unique to ECMA/Javascript (in usage).
(Score: 1) by kurenai.tsubasa on Wednesday September 07 2016, @02:40AM
Bah, shouldn't have hit submit so quickly. Sorry to reply to myself. The point of that construct is to create a self-contained scope. It's almost kind of like a class if done properly, but it's not.
(Score: 2) by JNCF on Wednesday September 07 2016, @03:15AM
The point of that construct is to create a self-contained scope.
Yeah, and he wasn't even opposed to the purpose of the construct, he was opposed to the positioning of the brackets. He preferred to wrap the parens around the invocation, a practice I found myself agreeing with:
(function () {
}());
I haven't written JavaScript like that since I started using build tools that allow proper modules -- though those build tools rely on this construct under the hood, so my final production code does use it.
(Score: 2) by jimshatt on Wednesday September 07 2016, @07:33AM
(Score: 1) by nitehawk214 on Wednesday September 07 2016, @03:48PM
Wait, both of the last 2 cases work? I assumed that only the last case worked as that is how I always see it done.
I like the middle one much more.
"Don't you ever miss the days when you used to be nostalgic?" -Loiosh
(Score: 2) by JNCF on Wednesday September 07 2016, @05:17PM
In most real cases, the outer parens aren't necessary. If you change your first example to be the value assigned to a variable, it will work:
var x = function(a) { alert(a); }('sucking eggs')
As for why we would want to add outer parens, it's a matter of human readability. Let's break this example up into multiple lines.
var x = function(a) {
alert(a);
}('sucking eggs')
Now, if you looked at the first line of that function, you could be forgiven for assuming that the value of x is currently a function (though of course x is undefined, since that is the value returned by the function). Let's look at it with parens:
var x = (function(a) {
alert(a);
}('sucking eggs'))
Reading the first line, you should already know that we're going to do something with that function before assigning anything to x.
My only real argument against dog-balls-style is that it sort of undermines and confuses this point, since the parens only actually encompass the anonymous function and the invocation that comes after the end-paren. Looking to the end of the parens, a reader could still assume that x was a function. Of course the invocation is right next to it, not broken off onto another line that's potentially off-screen, and I don't think this is nearly as important of a distinction for readability.
(Score: 2) by JNCF on Wednesday September 07 2016, @06:54PM
My only real argument against dog-balls-style is that it sort of undermines and confuses this point, since the parens only actually encompass the anonymous function and not the invocation that comes after the end-paren.
Fixed that for me.
(Score: 3, Insightful) by stormwyrm on Wednesday September 07 2016, @06:44AM
Numquam ponenda est pluralitas sine necessitate.
(Score: 2) by TheRaven on Wednesday September 07 2016, @08:12AM
sudo mod me up
(Score: 2) by FatPhil on Wednesday September 07 2016, @10:20PM
Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves