I was testing if block scope can be used to replace IIFEs to create "private" variables through closures. It was going well until tested in Safari 11.0.3 (11604.5.6.1.1), which supports block scope, but has a bug with blocks and closures, e.g.:
{
let i = 0;
function getNext() {
return i++;
}
}
// Chrome and Firefox
console.log(getNext()); // 0
console.log(getNext()); // 1
// Safari
console.log(getNext()); // ReferenceError: Can't find variable: i
Is there a work around other than keep using IIFEs? Or is Safari correct and everyone else has a bug?
PS. In strict mode, getNext isn't defined outside the block either.