{"id":156722,"date":"2020-09-16T09:02:21","date_gmt":"2020-09-16T01:02:21","guid":{"rendered":"http:\/\/4563.org\/?p=156722"},"modified":"2020-09-16T09:02:21","modified_gmt":"2020-09-16T01:02:21","slug":"args-fn-args-%e6%9c%89%e6%b2%a1%e6%9c%89%e5%9e%83%e5%9c%be%e5%9b%9e%e6%94%b6%e7%9a%84%e9%97%ae%e9%a2%98%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=156722","title":{"rendered":"(&#8230;args) =&gt; fn(&#8230;args) \u6709\u6ca1\u6709\u5783\u573e\u56de\u6536\u7684\u95ee\u9898\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  (&#8230;args) =&gt; fn(&#8230;args) \u6709\u6ca1\u6709\u5783\u573e\u56de\u6536\u7684\u95ee\u9898\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : az22c <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        js \u51fd\u6570\u67ef\u91cc\u5316\u6216\u8005\u5b9e\u73b0\u8bed\u6cd5\u7cd6\u7ecf\u5e38\u7528\u5230\u8fd9\u79cd\u903b\u8f91\uff1a<\/p>\n<p>const adder = (&#8230;args) =&gt; dispatch(&#8230;args)\u3002 \/\/ dispatch \u53ef\u4ee5\u4efb\u610f\u666e\u901a\u51fd\u6570\u3002<\/p>\n<p>\u6211\u770b\u5230 redux \u6e90\u7801\u91cc\u9762\u4e5f\u662f\u8fd9\u4e48\u7528\uff0c\u751a\u81f3\u5f88\u591a\u5f00\u6e90 react \u9879\u76ee\u662f\u8fd9\u4e48\u5199\u3002\u6700\u8fd1\u548c\u9762\u8bd5\u5b98\u8ba8\u8bba\uff0c\u5bf9\u65b9\u8bf4\u8fd9\u6837\u4f1a\u4ea7\u751f\u95ed\u5305\uff0c\u751a\u81f3\u6709\u5185\u5b58\u6cc4\u6f0f\u7684\u98ce\u9669\u3002<\/p>\n<p>\u6211\u56de\u5934 chrome \u518d\u6d4b\u8bd5\u8c03\u8bd5\u4e00\u4e0b\uff0c\u597d\u50cf\u6ca1\u6709\u770b\u5230\u6709\u95ed\u5305\u3002\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u6211\u7684\u7406\u89e3\u6709\u95ee\u9898      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3278582\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KuroNekoFan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u9762\u8bd5\u5b98\u8bb0\u6df7\u4e86\u5427,\u662f arguments object \u6709\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\uff0c\u800c\u4e14\u8ddf\u95ed\u5305\u6ca1\u5173\u7cfb<br \/>https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Functions\/arguments                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278583\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : FaiChou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u300c\u6709\u5185\u5b58\u6cc4\u6f0f\u7684\u98ce\u9669\u300d\u8fd9\u53e5\u8bdd\u600e\u4e48\u8bf4\u90fd\u662f\u6b63\u786e\u7684, \u8c01\u4e5f\u4e0d\u80fd\u4fdd\u8bc1\u6d4f\u89c8\u5668\u662f\u5426\u91ca\u653e\u5e94\u8be5\u88ab\u91ca\u653e\u7684\u53d8\u91cf. \u4f46 \u300c (&#8230;args) =&gt; dispatch(&#8230;args)\u300d\u8fd9\u4e48\u5199\u5e76\u6ca1\u6709\u5185\u90e8\u53d8\u91cf\u5440, \u6709\u5565\u597d\u6cc4\u6f0f\u7684 ?<\/p>\n<p>\u4e0d\u8fc7\u8fd8\u662f\u8981\u8bb2\u4e2a\u4f8b\u5b50(\u6d4f\u89c8\u5668\u7684 bug): https:\/\/bugs.chromium.org\/p\/chromium\/issues\/detail?id=315190<\/p>\n<p>var someClass = function() {<br \/> console.log(&#8216;some&#8217;);<br \/>};<\/p>\n<p>function getter() {<br \/> var some = new someClass();<br \/> if(true) {<br \/> return function() { \/\/I&#8217;m done with some and don&#8217;t need it<br \/> return null;<br \/> };<br \/> } else {<br \/> return function() {<br \/> return some;<br \/> };<br \/> }<br \/>}<\/p>\n<p>window.f = getter();<\/p>\n<p>\u8fd9\u4e2a\u4ee3\u7801\u6267\u884c\u5b8c\u7406\u8bba\u4e0a\u53d8\u91cf some \u4f1a\u88ab\u56de\u6536, \u56e0\u4e3a closure \u6ca1\u6709 catch \u4f4f some, \u4f46\u901a\u8fc7 devtools \u91cc memory &#8211; [heap snapshot] \u53ef\u4ee5\u53d1\u73b0 \u53d8\u91cf some \u6ca1\u6709\u88ab GC.<\/p>\n<p>\u6240\u4ee5, \u8fd9\u5c31\u662f\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u90fd\u6709\u300c\u6709\u5185\u5b58\u6cc4\u6f0f\u7684\u98ce\u9669\u300d.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278584\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : az22c <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @FaiChou \u4f60\u8fd9\u4e2a\u4f8b\u5b50\u662f\u7279\u6b8a\u60c5\u51b5\uff0c\u7f16\u8bd1\u7684\u65f6\u5019\u6ca1\u6cd5\u5206\u6790\u51fa if true \u3002\u611f\u89c9\u662f\u4e24\u56de\u4e8b\uff0c\u8bdd\u9898\u626f\u5f97\u6bd4\u8f83\u8fdc\u4e86\u3002<br \/>@KuroNekoFan \u662f \uff0c\u95ee\u9898\u8ba8\u8bba\u96c6\u4e2d\u5230\u5bf9 args \u7684\u5f15\u7528\u4e0a\uff0c\u6709\u6ca1\u6709\u95ed\u5305\u3002\u641e\u4e2a\u6d4b\u8bd5\u4ee3\u7801\u6d4b\u8bd5\u4e00\u4e0b\uff0c\u8fd8\u662f\u633a\u660e\u663e\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278585\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : soulmt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             what \u8fd9\u4f1a\u4ea7\u751f\u95ed\u5305\uff1f \u5e94\u8be5\u8bf4\u6709\u53ef\u80fd\u4f1a\u4ea7\u751f\u5427\uff0ces6 \u8fd9\u79cd\u7528\u6cd5\u4e0d\u662f\u5f88\u591a\u4e48\uff0c\u8d76\u7d27\u8dd1\u5427\uff0c\u8fd9\u8fd8\u9762\u5565                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278586\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : az22c <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @soulmt <br \/>@KuroNekoFan <br \/>\u597d\u50cf\u660e\u767d\u4e86<br \/>\u50cf react-redux\uff0c\u8fd9\u4e2a\u201cdispatch \u51fd\u6570\u201d\u662f\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u4f20\u5165\u672c\u51fd\u6570\u4e2d\uff0c\u6ca1\u6709\u95ed\u5305\u95ee\u9898\u3002<\/p>\n<p>function mapDispatchToProps(dispatch) {<br \/> return {<br \/> adder: (&#8230;args) =&gt; dispatch(&#8216;function name&#8217;, &#8230;args),<br \/> }<br \/>}<\/p>\n<p>connect(mapStateToProps, mapDispatchToProps)(Component)<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u800c\u5982\u679c\u8fd9\u4e2a dispatch \u51fd\u6570\u4f5c\u4e3a\u5f53\u524d\u51fd\u6570\u7684\u5185\u58f0\u660e\u7684\u51fd\u6570\uff0c\u5e76\u4e14\u8be5\u51fd\u6570\u8fd4\u56de adder\uff0c\u662f\u6709\u95ed\u5305\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278587\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KuroNekoFan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @az22c \u6309\u7167\u95ed\u5305\u7684\u5b9a\u4e49\uff0c\u5728\u4e00\u4e2a function \u91cc\u5728\u5b9a\u4e49\u4e00\u4e2a function \u5c31\u5f62\u6210\u4e86\u4e00\u4e2a\u95ed\u5305\uff0c\u4f46\u662f\u95ed\u5305\u8ddf\u5185\u5b58\u6cc4\u6f0f\u6ca1\u6709\u5fc5\u7136\u8054\u7cfb&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278588\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : finalwave <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @FaiChou #2 \u8fd9\u4e0d\u662f V8 \u540c\u4e00\u4f5c\u7528\u57df\u51fd\u6570\u5171\u7528\u5185\u5b58\u548c\u5757\u72b6\u4f5c\u7528\u57df\u5185\u51fd\u6570\u53d8\u91cf\u63d0\u5347\u641e\u51fa\u6765\u7684\u95ee\u9898\u561b\uff0c\u6362\u4e2a\u5f15\u64ce\u5c31\u597d\u4e86\uff08\u72d7\u5934                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278589\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : FaiChou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @finalwave #7 GC \u662f\u5f15\u64ce\u81ea\u5df1\u5b9e\u73b0\u7684, \u4ee3\u7801\u90fd\u662f\u6709 bug \u7684, \u6240\u4ee5\u5b83\u6709\u6cc4\u6f0f\u7684\u98ce\u9669 ( \u9003                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278590\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : usw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u548b\u7740\uff0c\u8fd8\u6307\u671b\u628a dispatch \u7ed9\u4f60\u56de\u6536\u6389                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3278591\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wxsm <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9047\u5230\u8fd9\u79cd\u60c5\u51b5\u5efa\u8bae\u8ffd\u95ee\uff1a\u5177\u4f53\u662f\u90a3\u4e00\u90e8\u5206\u7684\u5185\u5b58\u6cc4\u6f0f\uff1f\u600e\u4e48\u4e2a\u6cc4\u9732\u6cd5\uff1f\u600e\u4e48\u5199\u624d\u80fd\u4e0d\u6cc4\u9732\uff1f\u5982\u679c\u5bf9\u65b9\u4e0d\u61c2\uff0c\u90a3\u5c31\u66b4\u9732\u4e86\u3002\u5982\u679c\u771f\u61c2\uff0c\u90a3\u5c31\u5b66\u5230\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>(&#8230;args) =&#038;g&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/156722"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156722"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/156722\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156722"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}