Skip to content

Instantly share code, notes, and snippets.

@goatslacker
Created October 14, 2011 04:55
Show Gist options
  • Save goatslacker/1286282 to your computer and use it in GitHub Desktop.
Save goatslacker/1286282 to your computer and use it in GitHub Desktop.
// write about this, closures and prorotypes.
// can use this
// but new's need to be inside function
var baz = 0;
function Bar() {
this.ct = (baz += 1);
};
var Foo = function () {
this.a = 1;
};
Foo.prototype.b = (function () {
var c = 2;
var f = new Bar();
return function () {
c = 4;
return f.ct;
};
}());
var d = new Foo();
console.log(d.b());
var e = new Foo();
console.log(e.b());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment