Skip to content

Instantly share code, notes, and snippets.

@dce
Created September 4, 2011 21:44
Show Gist options
  • Save dce/1193561 to your computer and use it in GitHub Desktop.
Save dce/1193561 to your computer and use it in GitHub Desktop.
var util = require("util");
var clone = function(obj) {
var f = function() { };
f.prototype = obj;
return new f;
};
var person = {
name: "Person",
greeting: "Hello, I'm",
greet: function() {
util.puts(this.greeting + " " + this.name);
}
}
person.greet();
util.puts("---");
var david = clone(person);
david.name = "David";
person.greet();
david.greet();
util.puts("---");
var javid = clone(david);
javid.greeting = "Hola, soy";
person.greet();
david.greet();
javid.greet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment