{"id":426997,"date":"2021-04-12T23:01:19","date_gmt":"2021-04-12T15:01:19","guid":{"rendered":"http:\/\/4563.org\/?p=426997"},"modified":"2021-04-12T23:01:19","modified_gmt":"2021-04-12T15:01:19","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-jquery-%e7%9a%84-extend-%e6%96%b9%e6%b3%95%e6%97%a0%e6%b3%95%e5%9c%a8%e6%89%a9%e5%b1%95%e4%b8%ad%e8%8e%b7%e5%8f%96%e5%88%b0%e4%bc%a0%e5%85%a5%e7%9a%84%e9%93%be%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=426997","title":{"rendered":"\u4e3a\u4ec0\u4e48 jquery \u7684 extend \u65b9\u6cd5\u65e0\u6cd5\u5728\u6269\u5c55\u4e2d\u83b7\u53d6\u5230\u4f20\u5165\u7684\u94fe\u5f0f\u7684\u53c2\u6570 this\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e3a\u4ec0\u4e48 jquery \u7684 extend \u65b9\u6cd5\u65e0\u6cd5\u5728\u6269\u5c55\u4e2d\u83b7\u53d6\u5230\u4f20\u5165\u7684\u94fe\u5f0f\u7684\u53c2\u6570 this\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mostkia <\/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>\u6700\u8fd1\u5728\u5199 jq \u7684\u63d2\u4ef6\u65f6\uff0c\u5c1d\u8bd5\u8fd9\u6837\u4f7f\u7528\u4ee5\u4e0b\u7684\u7ed3\u6784\uff0c\u53d1\u73b0\u65e0\u8bba\u5982\u4f55\u90fd\u65e0\u6cd5\u83b7\u53d6\u5230 jquery \u7684\u94fe\u4e0a\u4f20\u9012\u8fc7\u6765\u7684 this\uff1a<\/p>\n<pre><code>\/\/\u6269\u5c55 jq $.fn.extend({     newFun: {         Fun_A: function(){             console.log(this);         },         Fun_B: function(){             \/\/\u66f4\u591a\u7684\u540c\u7ea7\u65b9\u6cd5         }     } }); \/\/\u6267\u884c\u65f6 $().newFun.Fun_A(); \/\/\u7ed3\u679c\u6ca1\u6709\u62ff\u5230$\u5165\u53e3\u7684\u53c2\u6570 {Fun_A: \u0192} <\/code><\/pre>\n<p>\u7136\u800c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u65f6\uff0c\u5219\u53ef\u4ee5\u83b7\u53d6\u5230\u8fd9\u4e2a$(&#8216;div&#8217;)\u4f20\u5165\u7684\u53c2\u6570\uff0c<\/p>\n<pre><code>\/\/\u6269\u5c55 jq $.fn.extend({     newFun: function(){         console.log(this)     } }); \/\/\u6267\u884c\u65f6 $('div').newFun(); \/\/\u7ed3\u679c\u62ff\u5230\u4e86\u53c2\u6570 init(3)\u00a0[div#imgsgls, div#imgs2gls, div, prevObject: init(1), context: document, selector: \"div\"] <\/code><\/pre>\n<p>\u60f3\u60f3\u4e5f\u4e0d\u5947\u602a\uff0cthis \u672c\u8eab\u5c31\u662f\u6839\u636e\u73af\u5883\u4e0d\u65ad\u53d8\u5316\u7684\uff0c\u4f46\u6211\u9700\u8981$()\u91cc\u9762\u4f20\u5165\u7684\u53c2\u6570 \u6709\u4ec0\u4e48\u529e\u6cd5\u80fd\u83b7\u5f97\u5417\uff1f\u662f\u6211\u5ffd\u7565\u4e86\u624b\u518c\u4e0a\u7684\u4e1c\u897f\uff0c\u8fd8\u662f\u8bf4\u539f\u672c jq \u8bbe\u8ba1\u5c31\u65e0\u6cd5\u83b7\u53d6\u5230\u8fd9\u4e2a\u53c2\u6570\u7684\u5462\uff1f \u56e0\u4e3a\u4ee5\u524d\u90fd\u662f\u76f4\u63a5\u8c03\u7528\u5185\u7f6e\u7684\u65b9\u6cd5\uff0c\u6ca1\u81ea\u5df1\u5199\u8fc7\u6269\u5c55\uff0c\u6ca1\u60f3\u5230\u7b2c\u4e00\u6b21\u5199\u5c31\u9047\u5230\u56f0\u96be\u4e86\u3002\u7f51\u4e0a\u4e5f\u67e5\u4e86\u8d44\u6599\uff0c\u4f3c\u4e4e\u6ca1\u6709\u76f8\u5173\u7684\u4fe1\u606f\uff0c\u662f\u6211\u5199\u6cd5\u592a\u5201\u94bb\u4e86\u5417\uff1f\u83dc\u9e1f\uff0c\u6c57\u989c\uff0c\u5e0c\u671b v \u53cb\u4e0d\u541d\u556c\u8d50\u6559<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5735040\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaoming1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             $.fn.extend({<br \/>* newFunc() {<br \/>* * const that = this<\/p>\n<p>* * const funcA = function funcA() {<br \/>* * * console.log(that === this)<br \/>* * }<\/p>\n<p>* * return {<br \/>* * * funcA: funcA.bind(that),<br \/>* * }<br \/>* }<br \/>})<\/p>\n<p>\u7528\u7684\u65f6\u5019\u5c31 $(&#8220;div&#8221;).newFunc().funcA() \u5427<\/p>\n<p>PS 1202 \u5e74\u4e86\u600e\u4e48\u8fd8\u7528 jq&#8230;                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5735041\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : mostkia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xiaoming1992 jquery \u633a\u597d\u7528\u7684\uff0c\u800c\u4e14\u6211\u5199\u63d2\u4ef6\u4e5f\u662f\u60f3\u95f4\u63a5\u7684\u4e86\u89e3\u4e00\u4e0b\u8fd9\u73a9\u610f\u7684\u8bbe\u8ba1\u601d\u8def\uff0c\u5426\u5219\u6302\u9760\u4e0d\u4e0a\u53bb\u6211\u76f4\u63a5\u81ea\u5df1\u9020\u4e2a\u8f6e\u5b50\u4e0d\u9999\u561b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5735042\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : mostkia <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xiaoming1992 \u5df2\u89e3\u51b3\u95ee\u9898\uff0c\u611f\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5735043\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaoming1992 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mostkia \u55ef\u55ef\uff0c\u53ea\u662f\u73b0\u5728\u5982\u679c\u4e0d\u8ba9\u6211\u7528\u6269\u5c55\u8fd0\u7b97\u7b26\u3001\u7bad\u5934\u51fd\u6570\uff0c\u8ba9\u6211\u624b\u52a8\u6dfb\u52a0 css -ms- \u7b49\u524d\u7f00\u6211\u80af\u5b9a\u53d7\u4e0d\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48 jquery \u7684 exte&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\/426997"}],"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=426997"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/426997\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426997"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}