Created
February 7, 2015 18:35
-
-
Save zpao/7340ab4225840f168a72 to your computer and use it in GitHub Desktop.
PR 3085 Code
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
function b(a) { | |
return function() { | |
return a; | |
}; | |
} | |
var c = {b:"a", abbr:"abbr", c:"address", d:"area", a:"article", e:"aside"}, d = {}, e; | |
for (e in c) { | |
hasOwnProperty.call(c, e) && (d[e] = b.call(void 0, c[e])); | |
} | |
var g = "a abbr address area article aside".split(" ").reduce(function(a, f) { | |
a[f] = b(f); | |
return a; | |
}, {}); | |
console.log(d.a(), g.a()); |
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
// ==ClosureCompiler== | |
// @compilation_level ADVANCED_OPTIMIZATIONS | |
// @output_file_name default.js | |
// @formatting pretty_print | |
// ==/ClosureCompiler== | |
function mapObject(object, callback, context) { | |
if (!object) { | |
return null; | |
} | |
var result = {}; | |
for (var name in object) { | |
if (hasOwnProperty.call(object, name)) { | |
result[name] = callback.call(context, object[name], name, object); | |
} | |
} | |
return result; | |
} | |
function createDOMFactory(tag) { | |
// simplified | |
return function() { return tag }; | |
} | |
var ReactDOM = mapObject({ | |
a: 'a', | |
abbr: 'abbr', | |
address: 'address', | |
area: 'area', | |
article: 'article', | |
aside: 'aside' | |
}, createDOMFactory); | |
var ReactDOM2 = [ | |
'a', | |
'abbr', | |
'address', | |
'area', | |
'article', | |
'aside' | |
].reduce(function(DOM, tag) { | |
DOM[tag] = createDOMFactory(tag); | |
return DOM; | |
}, {}); | |
console.log(ReactDOM.article(), ReactDOM2.article()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment