Created
May 16, 2011 09:00
-
-
Save teramako/974120 to your computer and use it in GitHub Desktop.
どこかで見かけたProxyのサンプル
This file contains hidden or 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
var $ = Proxy.ceate({ | |
get: function (_, name) { | |
return function () { | |
var args = Array.prototype.slice.call(arguments); | |
var func = function (o) { | |
return o[name].apply(o, args); | |
}; | |
return func; | |
}; | |
} | |
}); | |
// -------------------------------------------- | |
// Example | |
// -------------------------------------------- | |
/* | |
["a","b","c"].map($.toUpperCase()); // ["A","B","C"] | |
same as | |
["a","b","c"].map(function(o){ return o.toUpperCase(); }) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment