Created
May 24, 2010 16:32
-
-
Save kkaefer/412097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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