Created
July 11, 2014 18:09
-
-
Save tav/00e2d39e2e806e7d1b8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> state = {user: 'tav', setUser: function(username) { | |
... console.log(this.user); | |
... this.user = username; | |
... }} | |
{ user: 'tav', setUser: [Function] } | |
> runCb = function(cb, value) { | |
..... cb(value); | |
..... } | |
[Function] | |
> runCb(state.setUser, 'seyi') | |
undefined | |
undefined | |
> keys = Object.keys(state) | |
[ 'user', 'setUser' ] | |
> for (var i = 0; i < keys.length; i++) { | |
..... key = keys[i]; | |
..... value = state[key]; | |
..... if (typeof value === 'function') { | |
....... state[key] = value.bind(state); | |
....... } | |
..... } | |
[Function] | |
> runCb(state.setUser, 'seyi') | |
tav | |
undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment