Skip to content

Instantly share code, notes, and snippets.

@mde
Created October 29, 2010 23:46
Show Gist options
  • Save mde/654680 to your computer and use it in GitHub Desktop.
Save mde/654680 to your computer and use it in GitHub Desktop.
node> var parentFunc = function () { this.a = []; };
node> typeof parentFunc;
'function'
node> var foo = new parentFunc();
node> foo;
{ a: [] }
node> var subFunc = function () {};
node> subFunc.prototype = foo;
{ a: [] }
node> var bar = new subFunc();
node> bar.a;
[]
node> bar.a === foo.a;
true
node> var baz = new subFunc();
node> baz.a.push(1);
1
node> var otherSubFunc = subFunc;
node> foo.a;
[ 1 ]
node> bar.a;
[ 1 ]
node> baz.a;
[ 1 ]
node> bar.a = 'howdy';
'howdy'
node> foo.a;
[ 1 ]
node> bar.a;
'howdy'
node> baz.a;
[ 1 ]
node> bar;
{ a: 'howdy' }
node> baz;
{}
node> baz.a
[ 1 ]
node> var parentFunc = function () { this.b = {howdy: 'HOWDY'} };
node> foo;
{ a: [ 1 ] }
node> foo;
{ a: [ 1 ] }
node> bar;
{ a: 'howdy' }
node> delete bar.a;
true
node> bar;
{}
node> bar.a;
[ 1 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment