Created
October 19, 2012 13:29
-
-
Save DavidBruant/3918227 to your computer and use it in GitHub Desktop.
ProxyMap. Maybe what objects should have been?
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
"use strict"; | |
(function(global){ | |
var handler = new Proxy({ | |
get: function(target, name){ | |
return target.get(name); | |
}, | |
set: function(target, name, value){ | |
target.set(name, value); | |
return true; | |
}, | |
delete: function(target, name){ | |
return target.delete(name) | |
}, | |
has: function(target, name){ | |
return target.has(name) | |
} | |
}, | |
/*throwingMetaHandler*/ { | |
get: function(target, trap){ | |
var op = target[trap]; | |
if(typeof op !== 'function') | |
throw new Error('The trap '+trap+' cannot be used') | |
else | |
return target[trap]; | |
} | |
}); | |
global.ProxyMap = function ProxyMap(){ | |
return new Proxy(new Map(), handler); | |
} | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your comments. Weird at didn't get the notifications at the time...
@rwldrn what's the problem with the "use strict" outside the IIFE?