Created
May 5, 2014 20:17
-
-
Save johnjbarton/30c3e72d51d9d64e36d1 to your computer and use it in GitHub Desktop.
Proxy .__proto__ vs getPrototypeOf
This file contains 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
<script src="../third_party/harmony-reflect/reflect.js"></script> | |
<script name="testObjectCreate"> | |
(function() { | |
var aPrototype = {foo: 'foo'}; | |
function createProxy(obj) { | |
return Proxy(obj, { | |
get: function(target, name, receiver) { | |
console.log(' (Proxy handler \'get\' called for name = ' + name + ')'); | |
if (name === '__proto__') | |
return Object.getPrototypeOf(obj); | |
else | |
return Reflect.get(target, name, receiver); | |
} | |
}); | |
}; | |
var aProxy = createProxy(aPrototype); | |
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