Skip to content

Instantly share code, notes, and snippets.

@KOBA789
Created December 14, 2015 04:24
Show Gist options
  • Save KOBA789/e20160c7822ff36d7ff6 to your computer and use it in GitHub Desktop.
Save KOBA789/e20160c7822ff36d7ff6 to your computer and use it in GitHub Desktop.
function Parent () {
this._state = [];
}
Parent.prototype.foo = function (v) {
this._state.push(v);
};
Parent.prototype.bar = function () {
return this._state.join(',');
};
Parent.prototype.spawn = function () {
return new Child(this.foo.bind(this));
};
function Child (foo) {
this.foo = foo;
}
var p = new Parent();
var c = p.spawn();
c.foo(1);
c.foo(2);
console.log(p.bar());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment