Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created October 25, 2013 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/7162983 to your computer and use it in GitHub Desktop.
Save isaacs/7162983 to your computer and use it in GitHub Desktop.
function def() {
var myx;
Object.defineProperty(global, 'x', {
get: function() {
return myx;
},
set: function(val) {
console.log('setter!');
myx = val;
},
configurable: true,
enumerable: true
});
// This one is fine.
this.eval('var x = function y() {}');
console.log(myx.name, this.x.name);
// This one throws a redeclaration error if we didn't
// set configurable:true in the property. However,
// wtf? Doesn't call the setter!?
this.eval('function x() {}');
console.log(myx.name, this.x.name);
}
def();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment