Skip to content

Instantly share code, notes, and snippets.

@torgeir
Created August 18, 2010 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgeir/534661 to your computer and use it in GitHub Desktop.
Save torgeir/534661 to your computer and use it in GitHub Desktop.
js functional+prototypal inheritance template
var sys = require('sys');
var createObject = function (obj) {
function F () {};
F.prototype = obj;
return new F;
};
var button = (function () {
var defaultName = '';
var create = function (name) {
var button = createObject(buttonPrototype);
button.name = name || defaultName;
return button;
};
var buttonPrototype = {
toString: function () {
return 'Us buttons share this anonymous method!! ' + this.name;
}
};
return {
create: create
};
})();
var a = button.create('a');
var b = button.create('b');
var c = { name: "I don't, I am [object Object]" };
sys.puts(a);
sys.puts(b);
sys.puts(c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment