{"id":172569,"date":"2020-10-25T08:05:20","date_gmt":"2020-10-25T00:05:20","guid":{"rendered":"http:\/\/4563.org\/?p=172569"},"modified":"2020-10-25T08:05:20","modified_gmt":"2020-10-25T00:05:20","slug":"js-%e5%85%b3%e4%ba%8e-this-%e6%8c%87%e5%90%91%e7%9a%84%e7%96%91%e6%83%91","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=172569","title":{"rendered":"JS \u5173\u4e8e this \u6307\u5411\u7684\u7591\u60d1"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  JS \u5173\u4e8e this \u6307\u5411\u7684\u7591\u60d1               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenpingan <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\/\/\u4ee3\u7801 var name = &#8216;\u884c\u661f\u98de\u884c&#8217;; let obj = { name: &#8216;\u542c\u98ce\u662f\u98ce&#8217;, fn: function () { console.log(this.name); } };<\/p>\n<p>function fn1(param) { param(); }; fn1(obj.fn);<\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u6211\u4eec\u5c06 obj.fn \u4e5f\u5c31\u662f\u4e00\u4e2a\u51fd\u6570\u4f20\u9012\u8fdb fn1 \u4e2d\u6267\u884c\uff0c\u8fd9\u91cc\u53ea\u662f\u5355\u7eaf\u4f20\u9012\u4e86\u4e00\u4e2a\u51fd\u6570\u800c\u5df2\uff0cthis \u5e76\u6ca1\u6709\u8ddf\u51fd\u6570\u7ed1\u5728\u4e00\u8d77\uff0c\u6240\u4ee5 this \u4e22\u5931\u8fd9\u91cc\u6307\u5411\u4e86 window \u3002<\/p>\n<p>\u4e0a\u8ff0\u662f\u4e00\u7bc7\u6587\u7ae0\u4e2d\u8bb2\u8ff0\u7684\uff0c\u6211\u6709\u70b9\u6ca1\u641e\u6e05\u695a\u201cthis \u5e76\u6ca1\u6709\u8ddf\u51fd\u6570\u7ed1\u5728\u4e00\u8d77\uff0c\u6240\u4ee5 this \u4e22\u5931\u8fd9\u91cc\u6307\u5411\u4e86 window\u201d\u8fd9\u53e5\u8bdd\u5230\u5e95\u8868\u8ff0\u4e86\u4ec0\u4e48\u610f\u601d&#8230;<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3880199\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Exceptionluo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             var name = &#8220;\u884c\u661f\u98de\u884c&#8221;;<br \/> let obj = {<br \/> name: &#8220;\u542c\u98ce\u662f\u98ce&#8221;,<br \/> fn: function () {<br \/> console.log(this.name);<br \/> \/\/\u54ea\u4e2a\u5bf9\u8c61\u8c03\u7528\u8be5\u65b9\u6cd5\uff0cthis \u5373\u6307\u5411\u8be5\u5bf9\u8c61<br \/> },<br \/> };<\/p>\n<p> function fn1(fn) {<br \/> \/*<br \/> \u8fd9\u91cc\u7684 fn \u53ea\u662f\u4e2a\u65b9\u6cd5\uff0c\u540c function () {<br \/> console.log(this.name);<br \/> }<br \/> \u8be5\u65b9\u6cd5\u5df2\u7ecf\u548c obj \u5bf9\u8c61\u6ca1\u6709\u5173\u7cfb\u4e86\uff0c\u6240\u4ee5\u6700\u7ec8\u7684 this \u5c31\u6307\u5411\u4e86\u515c\u5e95\u5bf9\u8c61 window \u5bf9\u8c61\uff0c\u91cc\u9762\u7684 this \u5c31\u662f window<\/p>\n<p> \u867d\u7136 fn \u5728 fun1 \u91cc\u6267\u884c,\u4f46\u662f fn \u4e0d\u5c5e\u4e8e fn1,\u8fd9\u91cc\u53ea\u662f\u501f\u7528\u7684\u5173\u7cfb<br \/> *\/<br \/> fn();<br \/> }<br \/> fn1(obj.fn);                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3880200\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : chenpingan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Exceptionluo \u6211\u6709\u70b9\u7406\u89e3\u4e86\uff0c\u8c22\u8c22\u4f60                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>JS \u5173\u4e8e this \u6307\u5411\u7684\u7591\u60d1 &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\/172569"}],"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=172569"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/172569\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172569"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}