Skip to content

Instantly share code, notes, and snippets.

@johnjbarton
Created May 5, 2014 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjbarton/f8a837104f0292fa088c to your computer and use it in GitHub Desktop.
Save johnjbarton/f8a837104f0292fa088c to your computer and use it in GitHub Desktop.
Proxy fails in Object.create()
<script src="../third_party/harmony-reflect/reflect.js"></script>
<script name="testObjectCreate">
(function() {
var aPrototype = {foo: 'foo'};
var handler = {
get: function(target, name, receiver) {
console.log(' (Proxy handler \'get\' called for name = ' + name + ')');
return target[name];
}
};
var aProxy = Proxy(aPrototype, handler);
var hasProxyAsProto = Object.create(aProxy);
console.log('hasProxyAsProto.__proto__: ',
hasProxyAsProto.__proto__);
console.log('hasProxyAsProto.__proto__ === aProxy ',
hasProxyAsProto.__proto__ === aProxy);
console.log('Object.getPrototypeOf(hasProxyAsProto) === aProxy ',
Object.getPrototypeOf(hasProxyAsProto) === aProxy);
console.log('hasProxyAsProto.__proto__ === aProxy.__proto__ ',
hasProxyAsProto.__proto__ === aProxy.__proto__);
console.log('--- Contrast with non-proxy results: ---')
var hasAPrototypeAsProto = Object.create(aPrototype);
console.log('hasAPrototypeAsProto.__proto__',
hasAPrototypeAsProto.__proto__);
console.log('hasAPrototypeAsProto.__proto__ === aPrototype ',
hasAPrototypeAsProto.__proto__ === aPrototype);
console.log('Object.getPrototypeOf(hasAPrototypeAsProto) === aPrototype ',
Object.getPrototypeOf(hasAPrototypeAsProto) === aPrototype);
console.log('hasAPrototypeAsProto.__proto__ === aPrototype.__proto__ ',
hasAPrototypeAsProto.__proto__ === aPrototype.__proto__);
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment