Skip to content

Instantly share code, notes, and snippets.

@nathanaschbacher
Created November 2, 2012 17:36
Show Gist options
  • Save nathanaschbacher/4002983 to your computer and use it in GitHub Desktop.
Save nathanaschbacher/4002983 to your computer and use it in GitHub Desktop.
Javascript instance to instance coercion
var inspect = require('util').inspect;
var Class1 = function Class1() {
this.frank = "costanza";
this.__defineGetter__('prop', function() {return 5;});
this.__defineGetter__('fromClass1', function() {return 5;});
}
Class1.prototype.heyThere = function() {}
var Class2 = function Class2() {
this.frank = "brasky";
}
Class2.highlevel = function() {};
Class2.prototype.seehere = null;
var c1 = new Class1();
var c2 = new Class2();
console.log(inspect(c1, true, null, null));
c2.__proto__ = c1;
console.log(inspect(c2, true, null, null));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment