Created
December 18, 2011 13:12
-
-
Save bga/1493382 to your computer and use it in GitHub Desktop.
basic.js
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
/* | |
case insensitive names! | |
*/ | |
var Basic = function(obj) { | |
var _transform = (function(){ | |
var cache = Object.create(null) | |
return function(name){ | |
return (cache[name] // lisp! | |
|| (cache[name] = | |
Object.getOwnPropertyNames(obj).filter(function(i){ return i.toUpperCase() == name.toUpperCase() })[0])) | |
} | |
})() | |
return Proxy.create({ | |
has: function(name) { return _transform(name) in obj }, | |
get: function(r, name) { return obj[_transform(name)] }, | |
set: function(r, name, v) { obj[_transform(name) || name] = v } | |
}, null) | |
} | |
var a = Basic({ | |
x: 1, | |
_foo: function(){ return this.x } | |
}) | |
a.X = 1 | |
a.Y = 2 | |
_log(a._Foo() + a.y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment