{"id":736,"date":"2010-10-23T21:53:56","date_gmt":"2010-10-23T13:53:56","guid":{"rendered":"http:\/\/leegorous.net\/blog\/?p=736"},"modified":"2012-03-03T19:39:22","modified_gmt":"2012-03-03T11:39:22","slug":"method-proxy-in-javascript","status":"publish","type":"post","link":"http:\/\/leegorous.net\/blog\/2010\/10\/23\/method-proxy-in-javascript\/","title":{"rendered":"Javascript \u4e2d\u7684 proxy \u5b9e\u73b0"},"content":{"rendered":"<p>\u73b0\u5728\u5199\u4ee3\u7801\u90fd\u6709\u4e2a\u503e\u5411\uff0c\u5c3d\u91cf\u7528\u7b80\u5355\u903b\u8f91\uff0c\u77ed\u5c0f\u7684\u8bcd\u6c47\u6765\u6784\u6210\uff0c\u751a\u81f3\u7528\u5230\u4e86\u5927\u91cf shortcut (\u53eb \u77ed\u540d \uff1f)\uff0c\u6bd4\u5982\u591a\u79cd\u6d4f\u89c8\u5668\u90fd\u63d0\u4f9b\u4e86<a href=\"http:\/\/getfirebug.com\/wiki\/index.php\/Console_API\" target=\"_blank\"> console API<\/a>\uff0c\u7528\u6765\u505a log \u662f\u4e0d\u9519\u7684\uff0c\u4f46\u662f\u5230\u5904\u90fd console.log(&#8230;) \u5e76\u4e0d\u600e\u4e48\u7406\u60f3\uff0c\u5982\u679c\u53ef\u4ee5\u7f29\u77ed\u6210 $.log(&#8230;) (\u4f7f\u7528 jquery )\u5c31\u633a\u597d\u7684\uff0c\u800c\u4e14\u8fd8\u6709\u5229\u4e8e\u5c4f\u853d\u5404\u79cd\u6d4f\u89c8\u5668\u7684\u5dee\u5f02\uff0c\u968f\u610f\u63a7\u5236\u662f\u5426\u542f\u7528\u65e5\u5fd7\u76d1\u63a7\u3002<\/p>\n<p>\u8fd9\u91cc\u5c31\u662f\u9700\u8981\u5c06 console.log \u8f6c\u6362\u6210 $.log\uff0c\u5f53\u7136\u8fd8\u6709\u5176\u5b83\u5982 error, info\u3002\u6700\u7b80\u5355\u7684\u60f3\u6cd5\u5c31\u662f <\/p>\n<pre name=\"code\" class=\"brush: js\">\r\nif (window.console) {\r\n    $.log = console.log \r\n} else {\r\n    $.log = function() {}\r\n}\r\n<\/pre>\n<p>\u4e0d\u8fc7\uff0c\u8fd9\u4e2a\u505a\u6cd5\u4ec5\u4ec5\u5f97\u5230 firebug \u7684\u652f\u6301\uff0c\u5728 webkit \u4e2d\u4f1a\u62a5\u544a Uncaught exception\uff0c\u90a3\u5c1d\u8bd5\u63d0\u4f9b\u4e00\u4e2a console \u7684 proxy\uff1f<br \/>\n\u5728 Java \u4e2d\u771f\u662f\u5c0f\u83dc\u4e00\u789f\uff0cjs \u91cc\u4e5f\u4e0d\u96be\uff1a<\/p>\n<pre name=\"code\" class=\"brush: js\">\r\n$.log = function() {\r\n    console.log.apply(console, arguments);\r\n}\r\n<\/pre>\n<p>\u4e0d\u8fc7\uff0c\u95ee\u9898\u5c31\u662f\u600e\u4e48\u770b\uff0c\u600e\u4e48\u4e0d\u4f18\u96c5\uff0c\u592a\u5570\u55e6\uff0c\u8fd8\u662f\u539f\u6765\u90a3\u4e2a\u5bf9\u8c61\uff0capply \u540e\u4f9d\u7136\u662f console\uff0c \u8fd8\u662f\u90a3\u4e2a\u65b9\u6cd5\uff0clog\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u4f20\u9012\u4e00\u4e0b\u53c2\u6570\u3002\u662f\u4e0d\u662f\u6709\u70b9\u8822\u4e86\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5c31\u6ca1\u6709\u7136\u540e\u4e86\u3002\u6211\u6ca1\u529e\u6cd5\u8ba9\u5b83\u66f4\u4f18\u96c5\u4e86\u3002<\/p>\n<p>\u60f3\u8981\u5f97\u5230\u4e00\u4e2a\u7f29\u7565\u7684\u7528\u6cd5 $.log(&#8230;)\uff0c\u662f\u6709\u4ee3\u4ef7\u7684\uff0c\u4e0d\u8fc7\u8fd8\u662f\u503c\u5f97\u7684\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u57fa\u4e8e\u4ee5\u524d\u7684\u5b9e\u9a8c\uff0c\u5927\u91cf\u7684 apply \u4f1a\u660e\u663e\u5f71\u54cd\u6027\u80fd\uff0c\u6240\u4ee5\uff0capply \u6709\u98ce\u9669\uff0c\u4f7f\u7528\u9700\u8c28\u614e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u5728\u5199\u4ee3\u7801\u90fd\u6709\u4e2a\u503e\u5411\uff0c\u5c3d\u91cf\u7528\u7b80\u5355\u903b\u8f91\uff0c\u77ed\u5c0f\u7684\u8bcd\u6c47\u6765\u6784\u6210\uff0c\u751a\u81f3\u7528\u5230\u4e86\u5927\u91cf shortcut (\u53eb \u77ed\u540d \uff1f)\uff0c\u6bd4 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/leegorous.net\/blog\/2010\/10\/23\/method-proxy-in-javascript\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cJavascript \u4e2d\u7684 proxy \u5b9e\u73b0\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[102],"tags":[9],"_links":{"self":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/736"}],"collection":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":3,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":1065,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/posts\/736\/revisions\/1065"}],"wp:attachment":[{"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leegorous.net\/blog\/wp-json\/wp\/v2\/tags?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}