The last hour was spent exhaust coding some broadcast message bits with socket.io. In the middle of this I wrote a small function that reassignes itself after it is called; a one-shot setter.
Expanding slightly on this a little bit I wrote two generic gists demonstrating this in getter and setter fashion.
Getter Example
Here we simply replace the function with another function that returns the initially given value.
Setter Example
The setter example is a bit more complex. In order to correctly scope the passed function we create a copy of it, substituting the current context.
This context can even be altered externally by binding this
, ala error.bind(context)(handler);
.