{"rsdb":{"rid":"239280","subhead":"","postdate":"0","aid":"164925","fid":"107","uid":"1","topic":"1","content":"
\n

\u539f\u578b\u7ee7\u627f<\/h2> \n

\u7236\u7ea7\uff1a<\/strong><\/p> \n

    function Parent(name){\n        this.name=name;\n    }\n    Parent.prototype.sayHello=function(){\n        console.log("Hello,"+this.name);\n    }<\/code><\/pre> \n 
    \n
  1. \u539f\u578b\u94fe\u7ee7\u627f<\/p>

    function Kid(){};\nKid.prototype=new Parent("who");\n\nvar k=new Kid();\nconsole.log(k.name); \/\/who\nconsole.log(k.sayHello()); \/\/Hello,who<\/code><\/pre> 

    \u5f0a\u7aef\uff1a<\/strong>\u521b\u5efa\u5b9e\u4f8b\u65f6\u65e0\u6cd5\u5411\u7236\u7ea7\u4f20\u53c2<\/p><\/li> \n

  2. \u6784\u9020\u7ee7\u627f<\/p>

    function Kid(name){\n    Parent.call(this,name);\n};\n\nvar k=new Kid("who");\nconsole.log(k.name); \/\/who\nconsole.log(k.sayHello()); \/\/error<\/code><\/pre> 

    \u5f0a\u7aef\uff1a<\/strong>\u65e0\u6cd5\u83b7\u53d6\u7236\u7ea7\u539f\u578b\u94fe\u5c5e\u6027<\/p><\/li> \n

  3. \u5b9e\u4f8b\u7ee7\u627f<\/p>

    function Kid(name){\n    var p=new Parent(name);\n    return p;\n};\n\nvar k=new Kid("who");\nconsole.log(k.name); \/\/who\nconsole.log(k.sayHello()); \/\/Hello,who<\/code><\/pre> 

    \u5f0a\u7aef\uff1a<\/strong>\u5b9e\u4f8b\u662f\u7236\u7ea7\u7684\u5b9e\u4f8b<\/p><\/li> \n

  4. \u62f7\u8d1d\u7ee7\u627f<\/p>

    function Kid(name){\n    var p=new Parent(name);\n    for(var item in p){\n        Kid.prototype[item]=p[item];\n    }\n}\n\nvar k=new Kid("who");\nconsole.log(k.name); \/\/who\nconsole.log(k.sayHello()); \/\/Hello,who<\/code><\/pre> 

    \u5f0a\u7aef\uff1a<\/strong>\u592a\u5360\u7528\u5185\u5b58<\/p><\/li> \n

  5. \u7ec4\u5408\u7ee7\u627f<\/p>

    function Kid(name){\n    Parent.call(this,name);\n}\nKid.prototype=new Parent();\n\nvar k=new Kid("who");\nconsole.log(k.name); \/\/who\nconsole.log(k.sayHello()); \/\/Hello,who<\/code><\/pre> 

    \u5f0a\u7aef\uff1a<\/strong>\u8c03\u7528\u4e86\u4e24\u6b21\u7236\u7c7b\u6784\u9020\u51fd\u6570<\/p><\/li> \n

  6. \u5bc4\u751f\u7ec4\u5408\u7ee7\u627f<\/p>

    function Kid(name){\n    Parent.call(this,name);\n}\n(function(){\n    var p=function(){};\n    p.prototype=Parent.prototype;\n    Kid.prototype=new p();\n})()<\/code><\/pre> 

    \u5f0a\u7aef\uff1a<\/strong>\u5199\u6cd5\u6bd4\u8f83\u7e41\u7410<\/p><\/li> \n <\/ol> \n<\/div>","orderid":"0","title":"\u539f\u578b\u7ee7\u627f\u7684\u51e0\u79cd\u65b9\u5f0f","smalltitle":"","mid":"0","fname":"Web","special_id":"0","bak_id":"0","info":"0","hits":"9275","pages":"1","comments":"0","posttime":"2017-10-16 18:19:18","list":"1508149158","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u539f\u578b<\/A> \u7ee7\u627f<\/A> \u65b9\u5f0f<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.108.110.181","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u539f\u578b\u7ee7\u627f\u7684\u51e0\u79cd\u65b9\u5f0f","lastview":"1711719240","digg_num":"1500","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}