
var template = {"url":"http://jsbin.com/akiqa3/4","html" : "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=utf-8 \/>\n<title>JS Bin<\/title>\n<!--[if IE]>\n  <script src=\"http:\/\/html5shiv.googlecode.com\/svn\/trunk\/html5.js\"><\/script>\n<![endif]-->\n<style>\n  article, aside, figure, footer, header, hgroup, \n  menu, nav, section { display: block; }\n  #hello { height: 1100px; }\n<\/style>\n<\/head>\n<body>\n  <p id=\"hello\">Hello World<\/p>\n<\/body>\n<\/html>","javascript":"Array.prototype.invoke = function () {\n    var args = Array.prototype.slice.call(arguments),\n        method = args.shift(),\n        context = (Object.prototype.toString.call(method) === '[object Function]') ?\n                  'func' :\n                  'global',\n        actions = {\n            'func': function (param) {\n                var r;\n\n                args.unshift(param);\n                r = method.apply(null, args);\n                args.shift();\n\n                return r;\n            },\n            'global': function (v) {\n                var params = function (a) {\n                        return a.map(function (value) {\n                            var valueType = Object.prototype.toString.call(value),\n                                actions = {\n                                    '[object String]': function (x) { return '\"' + x + '\"'; },\n                                    '[object Array]': function (x) { return params(x); }\n                                };\n                            \n                            return ((valueType in actions) ? actions[valueType](value) : value);\n                        });\n                    },\n                    p,\n                    r;\n\n                args.unshift(v);\n                if (args.length === 1 && Object.prototype.toString.call(args[0]) !== '[object Array]') {\n                    r = window[method](v);\n                } else {\n                    p = params(args).join(', ');\n                    try {\n                        r = window[method].apply(null, p);\n                    } catch (e) {\n                        r = eval( \/\/sorry but ie leaves me with no other choice...\n                            'window.' + method + '(' + p + ')'\n                        );\n                    }\n                }\n                args.shift();\n\n                return r;\n            }\n        };\n\n    return this.map(function (value) {\n        try {\n            var isLocal = !!(method in value);\n        } catch (e) {\n            var isLocal = false;\n        }\n        try {\n            var isPrototype = !!(method in value.constructor.prototype);\n        } catch (e) {\n            var isPrototype = false;\n        }                    \n        \n        actions.local = (isLocal) ?\n            function () {\n                return value[method].apply(value, args);\n            } :\n            undefined;\n        actions.proto = (isPrototype) ?\n            function () {\n                return value.constructor.prototype[method].apply(value, args);\n            } :\n            undefined;\n        context = (isLocal) ? 'local' :\n                  (isPrototype) ? 'proto' :\n                  context;\n                  \n        return actions[context](value);\n    });\n};\n\nvar punch = function (v) {\n  alert('--==] ' + v);\n  return v + ' KOed';\n};\n\n['one','two'].invoke('alert');\n['three','four'].invoke('prompt', 'default...');\n['five','six'].invoke(punch);\nalert(['seven','eight'].invoke('toUpperCase').invoke(punch).join('\\r\\n'));\ndocument.getElementById('hello').innerHTML = [\n  {s:'one',hit: function () { return  this.s + ' says, \"OUCH!\"'; }},\n  {s:'two',hit: function () { return this.s + ' yells, \"Hey!\"'; }}\n].invoke('hit').join('<br \/>');\n[[0,1100],[0,0]].invoke('scrollTo');\n"}
