Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34776
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: No need for IIFEs any more? |
| Date | 2018-03-13 18:43 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <p89gkv$142r$1@gioia.aioe.org> (permalink) |
| References | <1c492da9-76d8-4c70-8c73-1c6e2f8baa23@googlegroups.com> |
On 13/03/2018 01:42, RobG wrote:
> Since block scoped variables were introduced in ECMAScript 2015,
> it's been possible to implement the same "private variable" functionality as
> is available using the IIFE pattern.
> [snip]
You may replace an IIFE with a block and a let or const declaration
(*don't use 'var' in this case*) or a module in ES6. There were some
examples of that in the book 'Exploring ES6', section 12.3.5, by Dr.
Axel Rauschmayer:
<http://exploringjs.com/es6/ch_callables.html#sec_iifes-in-es6>
There's also the possibility of using an Immediately-Invoked Arrow
Function (IIAF) in ES6. For example:
/*jshint esnext: true */
(() => {
// code.
})();
BTW, your getNext() function may be refactored to a Generator in ES6:
/*jshint esnext: true */
{
let gen = (function* idGen() {
let i = 0;
while(true) yield i++;
}());
console.log(gen.next()); // 0
console.log(gen.next()); // 1
console.log(gen.next()); // 3
}
--
Joao Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
No need for IIFEs any more? RobG <rgqld@iinet.net.au> - 2018-03-12 21:42 -0700
Re: No need for IIFEs any more? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-03-13 13:27 -0700
Re: No need for IIFEs any more? RobG <rgqld@iinet.net.au> - 2018-03-15 21:47 -0700
Re: No need for IIFEs any more? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2018-03-13 18:43 -0300
Re: No need for IIFEs any more? RobG <rgqld@iinet.net.au> - 2018-03-15 21:54 -0700
csiph-web