> re@Ben
1. `persist` because didn’t want to bring in the dark connotation associated
with `static` variables in C++. Although `persist` is just an example to prove
a point, could be anything really (even `static` 😊)
2. As for my knowledge and understanding, I’d imagine these to behave just
like closures w/ IIFE
```javascript
function foo(n) {
// initialized on first call to foo, persists for subsequent calls
persist let counter = 0;
// this way JS engine won't have to recompile the pattern everytime
persist const httpRE = /^https?/;
counter++;
return n * a;
}
```
is 1:1 as
```javascript
let foo = (() => {
let counter = 0;
const httpRE = /^https?/;
return (n) => {
counter++;
return n * a;
}
})()
```
Revisions to this are welcome of course
1. Ref #2
2. Umm…. Lets just say the fact we need to preserve state (like `counter` or
`lastValue`) is good enough selling point
3. This proposal aims for and enforces, once again, the motto that stuff
should “live” where it “belongs” and not “leak” out unnecessarily
4. Ref #5 and also see my reply to jhpratt that explains how this fails when
class methods are in question (see `DBService` class example)
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss