Skip to content

Instantly share code, notes, and snippets.

@kkaefer
Created May 24, 2010 16:32
Show Gist options
  • Save kkaefer/412097 to your computer and use it in GitHub Desktop.
Save kkaefer/412097 to your computer and use it in GitHub Desktop.
var sys = require('sys');
function Child() {}
// Defined on the prototype.
Object.defineProperty(Child.prototype, 'foo', { enumerable: false, value: 'test', writable: true });
Object.defineProperty(Child.prototype, 'bar', { enumerable: false, value: 'test2', writable: true });
var test = new Child;
// Defined local to the object "instance".
Object.defineProperty(test, 'baz', { enumerable: false, writable: true });
test.foo = 'bar'; // "overwrites" enumerable value of 'foo'.
test.baz = 'test3';
for (var key in test) {
sys.puts(key); // --> foo
}
sys.puts('----');
sys.puts(test.foo); // --> bar
sys.puts(test.bar); // --> test2
sys.puts(test.baz); // --> test3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment