Skip to content

Instantly share code, notes, and snippets.

@basecode
Created July 17, 2012 20:18
Show Gist options
  • Save basecode/3131784 to your computer and use it in GitHub Desktop.
Save basecode/3131784 to your computer and use it in GitHub Desktop.
non-writable factory functions
// class+constructor
var Lib = function() {
// instance variable
this.aVariable = 0;
// instance method
this.changeVariable = function(value) {
this.aVariable = value;
return this;
};
}
// factory
Lib.factory = Object.create(null, {
fork: {
value: function(value) {
return new Lib().changeVariable(value);
}
}
/* more factory functions */
});
with(Lib.factory) {
console.log(fork);
var fork = "";
console.log(fork(150).aVariable);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment