It's not a situation, but rather in my eyes a cleaner way of declaration. Have you read the article? Also, having this, makes it more explicit, as it should pass down values in a one way flow. Here's a gist with an example: https://goo.gl/1qyjNl . This distracts us a bit from the scenario though, as I was trying to tell @brendaneich ( and was wrong about) over Twitter.
The main idea is to make the copy of the variable prefixed with a standard name, so `var item = item || 'hello'` would have the RHS to be more intuitive and isolated from the actual variable name. As explained in the article , it might seem like a big load of nonsense, but I think It would be well worth the cause. On Tue, Apr 19, 2016 at 3:22 AM, Michael Theriot < michael.lee.ther...@gmail.com> wrote: > What scenarios do you need to declare a new variable equal to its current > declaration or a default value? > > On Sun, Apr 17, 2016 at 8:21 AM, even stensberg <evenstensb...@gmail.com> > wrote: > >> I've seen a lot of code using an extra type to have as a fallback. This >> to me seems like not a very good way of putting use of the logical OR. >> Here's an example: >> >> `var itemList = itemList || 'something went extremely wrong'` >> >> >> This is a really hacky way of doing things. I don't think you should >> assign your variable to a default by doing this. >> >> >> Been back and forth by this "issue" with some of the ReactJS members at >> GitHub, and while saying this is a "stylus" thing, I disagree. It is more >> about not reiterating your code. >> >> Options could be: >> >> -tenaries - long & !clean codelines >> -default params (ES) , though it won't be a general use case >> >> There is already a lot of assignment, string and so on operators, but I >> don't really seem any of them touch this, except maybe the bit-wise OR >> assignment Operator. To read more about that, check these two links out: >> >> https://msdn.microsoft.com/en-us/library/81bads72(v=vs.94).aspx >> http://web.eecs.umich.edu/~bartlett/jsops.html >> http://stackoverflow.com/a/14871137/5893008 >> >> And that is really not the use case here. We don't want a bit-wise, we >> want a logical OR. >> >> So here is what I come up with. It's not rocket science but ... nah, it's >> pretty straight forward.. >> >> `var listItem || = 'I love open source!'` >> >> >> For me, this is one thousand times more clean and it makes sense. >> JavaScript teaches us and wants us to use `+ =`,` - =` and any other >> type of "abbreviation" , so this makes perfectly sense for me. Either I'm >> crazy, but it seems like this should have been implemented a long time ago. >> ( Perhaps I'm both). >> >> Implementation will be another issue, but let us discuss that too( just >> keep in mind this is conceptional) >> >> >> Without further ado, I leave this up to you to discuss, and hopefully a >> champion to fetch up to the committee. >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss