Created
May 30, 2012 17:33
-
-
Save valueof/2837820 to your computer and use it in GitHub Desktop.
Without running this code could you tell me its output?
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
Object.defineProperty(Object.prototype, "foo", { | |
set: function (v) { | |
console.log("hello:", v); | |
}, | |
configurable: true} | |
); | |
var obj = { foo: "bar" }; | |
var obj2 = {}; | |
obj2.foo = "bar2"; |
Defining in literal never fallbacks to prototype, it's always about setting own properties. var obj = { foo: "bar" }
is same as:
var obj = Object.create(Object.prototype, {
foo: { value: 'bar', configurable: true, enumerable: true, writable: true }
}))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello:bar2
(EDIT: removed the space. Twas a typo.)