hasharray / revaluate.js

non destructive code revaluation
https://revaluate.js.org
2 stars 0 forks source link

WIP: Rewrite closures into mutable objects #11

Closed caspervonb closed 5 years ago

caspervonb commented 8 years ago

This rewrites identifiers in such a way that closures become tangible objects with late-lazy initialisation.

For example, take the following potential closures

setTimeout(function beep() {
  setTimeout(function boop() {
    console.log(typeof value);
    setTimeout(beep);
  }, 1000);
}, 1000);

Change that into the following

setTimeout(function beep() {
  var value = 0;
  setTimeout(function boop() {
    console.log(typeof value);
    setTimeout(beep);
  }, 1000);
}, 1000);

Previously, this would continue to output undefined but with this it will reflect the intended change and output number.

This can also unblock #9, since closures are mutable and accessible there is no need to evaluate in-place.

caspervonb commented 8 years ago

Demo

Late bindings