{"id":134413,"date":"2020-07-08T06:25:25","date_gmt":"2020-07-07T22:25:25","guid":{"rendered":"http:\/\/4563.org\/?p=134413"},"modified":"2020-07-08T06:25:25","modified_gmt":"2020-07-07T22:25:25","slug":"%e6%b1%82%e5%8a%a9%e5%a4%a7%e4%bd%ac%ef%bc%8c%e5%85%b3%e4%ba%8e-javascript-%e4%b8%ad-new-fun-%e7%9a%84%e7%a7%81%e6%9c%89%e5%b1%9e%e6%80%a7%e7%9a%84%e9%97%ae%e9%a2%98%e3%80%82","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=134413","title":{"rendered":"\u6c42\u52a9\u5927\u4f6c\uff0c\u5173\u4e8e JavaScript \u4e2d new fun() \u7684\u79c1\u6709\u5c5e\u6027\u7684\u95ee\u9898\u3002"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u52a9\u5927\u4f6c\uff0c\u5173\u4e8e JavaScript \u4e2d new fun() \u7684\u79c1\u6709\u5c5e\u6027\u7684\u95ee\u9898\u3002               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imdong <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u4e00\u4e2a\u9875\u9762\u4e2d\uff0c\u540c\u4e00\u4e2a\u5bf9\u8c61\u4f1a\u88ab\u521b\u5efa\u591a\u4e2a\u5b9e\u4f8b\uff0c\u540c\u65f6\u8fd9\u4e9b\u5b9e\u4f8b\u662f\u76f8\u4e92\u72ec\u7acb\u8fd0\u884c\u7684\u3002<\/p>\n<p>\u4f46\u662f\u5b9e\u4f8b\u4e2d\u6709\u4e00\u4e9b\u79c1\u6709\u5c5e\u6027\u4e0d\u60f3\u5bf9\u5916\u66b4\u9732\uff0c\u800c\u4e14\u6bcf\u4e2a\u5b9e\u4f8b\u95f4\u5c5e\u6027\u4e5f\u662f\u72ec\u7acb\u7684\u3002<\/p>\n<p>\u5927\u6982\u5e94\u8be5\u662f\u8fd9\u6837<\/p>\n<pre><code>let Obj = function(n){     this.num = n + Math.random(); }; Obj.prototype.get = function(){     console.log(this.num); }  let a = new Obj(1),     b = new Obj(2);  a.get(); \/\/ 1.xxx b.get(); \/\/ 2.xxx  \/\/ \u4e14\u6ee1\u8db3\u5982\u4e0b console.log(a.num); \/\/ undefined console.log(b.num); \/\/ undefined <\/code><\/pre>\n<p>\u76ee\u524d\u80fd\u60f3\u5230\u7684\u529e\u6cd5\u53ea\u6709\u5982\u4e0b\u8fd9\u6837\u4f3c\u4e4e\u975e\u5e38\u4e0d\u4f18\u96c5\u7684\u65b9\u6cd5\u3002<\/p>\n<pre><code>(function (window) {     \/**      * \u521b\u5efa\u4e00\u4e2a\u79c1\u6709\u7684\u6570\u636e\u5b58\u50a8\u65b9\u6cd5      *\/     let data = [],         dataBucket = function () {             if (!this instanceof Obj) {                 return null;             }             return data[this.data_id];         }      let obj = function (n) {         this.data_id = data.length + 1;         data[this.data_id] = {};          this.data().num = n + Math.random();     };     \/\/ \u6620\u5c04\u8bfb\u5199\u5230\u79c1\u6709\u65b9\u6cd5\u4e0a     obj.prototype.data = function () {         return dataBucket.call(this);     }      obj.prototype.get = function () {         console.log(this.data().num);     }      window.Obj = obj; })(window);  let a = new Obj(1),     b = new Obj(2);  a.get(); \/\/ 1.xxx b.get(); \/\/ 2.xxx <\/code><\/pre>\n<p>\u6240\u4ee5\uff0c\u5927\u4f6c\u4eec\uff0c\u6709\u6ca1\u6709\u66f4\u597d\u7684\u65b9\u6cd5\uff1f\uff1f\uff1f<\/p>\n<p>\u6216\u8005\u662f\u539f\u751f\u6709\u65b9\u6cd5\uff0c\u662f\u6211\u592a\u83dc\u4e0d\u77e5\u9053\u5462\uff1f<\/p>\n<p>\u6c42\u97ad\u6253&#8230;<\/p>\n<p>======= \u66f4\u65b0\uff0c\u53d1\u5b8c\u8d34\u6709\u68c0\u67e5\u4e86\u4e00\u4e0b\uff0c\u53d1\u73b0 a.data() \u4f9d\u7136\u53ef\u4ee5\u8bbf\u95ee\uff0c\u5d29\u6e83\u4e86&#8230;<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2436689\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhyl <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u95ed\u5305\u5c31\u884c\u4e86\u3002\u5177\u4f53\u7684\u5c31\u662f\u5728\u6784\u9020\u51fd\u6570\u91cc\u76f4\u63a5\u5b9a\u4e49 getter\uff0cgetter \u8bbf\u95ee\u5c40\u90e8\u53d8\u91cf\u6784\u6210\u4e00\u4e2a\u95ed\u5305\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u52a9\u5927\u4f6c\uff0c\u5173\u4e8e JavaScrip&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\/134413"}],"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=134413"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134413\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134413"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}