{"id":4193,"date":"2015-10-08T17:05:11","date_gmt":"2015-10-08T09:05:11","guid":{"rendered":"https:\/\/sdeno.com\/?p=4193"},"modified":"2015-10-08T17:07:29","modified_gmt":"2015-10-08T09:07:29","slug":"js%e4%b8%adprototype%e3%80%81__proto__%e3%80%81constructor%e3%80%81object%e3%80%81function%e5%85%b3%e7%b3%bb%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=4193","title":{"rendered":"Js\u4e2dPrototype\u3001__proto__\u3001Constructor\u3001Object\u3001Function\u5173\u7cfb\u4ecb\u7ecd"},"content":{"rendered":"<p>Function\u3001Object\uff1aJs\u81ea\u5e26\u7684\u51fd\u6570\u5bf9\u8c61\u3002<br \/>\nprototype,\u6bcf\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u663e\u793a\u7684prototype\u5c5e\u6027,\u5b83\u4ee3\u8868\u4e86\u5bf9\u8c61\u7684\u539f\u578b(Function.prototype\u51fd\u6570\u5bf9\u8c61\u662f\u4e2a\u4f8b\u5916\uff0c\u6ca1\u6709prototype\u5c5e\u6027)\u3002<br \/>\n__proto__:\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u540d\u4e3a__proto__\u7684\u5185\u90e8\u9690\u85cf\u5c5e\u6027\uff0c\u6307\u5411\u4e8e\u5b83\u6240\u5bf9\u5e94\u7684\u539f\u578b\u5bf9\u8c61(chrome\u3001firefox\u4e2d\u540d\u79f0\u4e3a__proto__\uff0c\u5e76\u4e14\u53ef\u4ee5\u88ab\u8bbf\u95ee\u5230)\u3002\u539f\u578b\u94fe\u6b63\u662f\u57fa\u4e8e__proto__\u624d\u5f97\u4ee5\u5f62\u6210(note\uff1a\u4e0d\u662f\u57fa\u4e8e\u51fd\u6570\u5bf9\u8c61\u7684\u5c5e\u6027prototype)\u3002<br \/>\n\u5173\u4e8e\u4e0a\u9762\u63d0\u5230\u7684\u51fd\u6570\u5bf9\u8c61\uff0c\u6211\u4eec\u6765\u770b\u4ee5\u4e0b\u4f8b\u5b50\uff0c\u6765\u8bf4\u660e\uff1a<\/p>\n<pre>var o1 = {};\r\n var o2 =new Object();\r\n \r\n function f1(){}\r\n var f2 = function(){}\r\n var f3 = new Function('str','console.log(str)');\r\n \r\n f3('aabb'); \/\/ aabb\r\n console.log('typeof Object:'+typeof Object); \/\/function\r\n console.log('typeof Function:'+typeof Function); \/\/function\r\n console.log('typeof o1:'+typeof o1); \/\/object\r\n console.log('typeof o2:'+typeof o2); \/\/object\r\n console.log('typeof f1:'+typeof f1); \/\/function\r\n console.log('typeof f2:'+typeof f2); \/\/function\r\n console.log('typeof f3:'+typeof f3); \/\/function<\/pre>\n<ul style=\"color: #000000;\">\n<li>\u901a\u5e38\u6211\u4eec\u8ba4\u4e3ao1\u3001o2\u662f\u5bf9\u8c61\uff0c\u5373\u666e\u901a\u5bf9\u8c61\uff1bf1\u3001f2\u3001f3\u4e3a\u51fd\u6570\u3002<\/li>\n<li>\u4f46\u662f\u5176\u5b9e\u51fd\u6570\u4e5f\u662f\u5bf9\u8c61\uff0c\u662f\u7531Function\u6784\u9020\u7684\uff0c<\/li>\n<li>f3\u8fd9\u79cd\u5199\u6cd5\u5c31\u8ddf\u5bf9\u8c61\u7684\u521b\u5efa\u7684\u5199\u6cd5\u4e00\u6837\u3002f1\u3001f2\u6700\u7ec8\u4e5f\u90fd\u50cff3\u4e00\u6837\u662f\u6709Function\u8fd9\u4e2a\u51fd\u6570\u6784\u9020\u51fa\u6765\u7684<\/li>\n<li>f1\u3001f2\u3001f3\u4e3a\u51fd\u6570\u5bf9\u8c61\uff0cFunction\u8ddfObject\u672c\u8eab\u4e5f\u662f\u51fd\u6570\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p><span style=\"color: #000000;\">\u00a0 \u00a0\u00a0<\/span><span style=\"color: #000000;\">\u00a0 \u00a0<\/span><span style=\"color: #000000;\">Js\u4e2d\u6bcf\u4e2a\u5bf9\u8c61(null\u9664\u5916)\u90fd\u548c\u53e6\u4e00\u4e2a\u5bf9\u8c61\u76f8\u5173\u8054\uff0c<\/span><span style=\"color: #000000;\">\u901a\u8fc7\u4ee5\u4e0b\u4f8b\u5b50\u8ddf\u5185\u5b58\u6548\u679c\u56fe\u6765\u5206\u6790Function\u3001Object\u3001Prototype\u3001__proto__\u5bf9\u8c61<\/span><span style=\"color: #000000;\">\u95f4\u7684\u5173\u7cfb\u3002<\/span><\/p>\n<pre>function Animal(){\r\n \r\n }\r\n var anim = new Animal();\r\n \r\n console.log('***********Animal anim proto*****************');\r\n console.log('typeof Animal.prototype:' +typeof Animal.prototype); \/\/object \r\n console.log('anim.__proto__===Animal.prototype:'+(anim.__proto__===Animal.prototype)); \/\/true\r\n console.log('Animal.__proto__===Function.prototype:'+(Animal.__proto__===Function.prototype)); \/\/true\r\n console.log('Animal.prototype.__proto__===Object.prototype:'+(Animal.prototype.__proto__===Object.prototype)); \/\/true\r\n \r\n console.log('***********Function proto*****************');\r\n console.log('typeof Function.prototype:'+typeof Function.prototype); \/\/function\r\n console.log('typeof Function.__proto__:'+typeof Function.__proto__); \/\/function\r\n console.log('typeof Function.prototype.prototype:'+typeof Function.prototype.prototype); \/\/undefined\r\n console.log('typeof Function.prototype.__proto__:'+typeof Function.prototype.__proto__); \/\/object\r\n console.log('Function.prototype===Function.__proto__:'+(Function.prototype===Function.__proto__)); \/\/true\r\nconsole.log('***********Object proto*****************');\r\n console.log('typeof Object.prototype:'+typeof Object.prototype); \/\/object\r\n console.log('typeof Object.__proto__:'+typeof Object.__proto__); \/\/function\r\n console.log('Object.prototype.prototype:'+Object.prototype.prototype); \/\/undefied\r\n console.log('Object.prototype.__proto__===null:'+(Object.prototype.__proto__===null)); \/\/null\r\nconsole.log('***********Function Object proto\u5173\u7cfb*****************');\r\n console.log('Function.prototype===Object.__proto__:'+(Function.prototype===Object.__proto__)); \/\/true\r\n console.log('Function.__proto__===Object.__proto__:'+(Function.__proto__===Object.__proto__)); \/\/true\r\n console.log('Function.prototype.__proto__===Object.prototype:'+(Function.prototype.__proto__===Object.prototype)); \/\/true\r\n\/********************* \u7cfb\u7edf\u5b9a\u4e49\u7684\u5bf9\u8c61Array\u3001Date ****************************\/\r\n console.log('**************test Array\u3001Date****************'); \r\n var array = new Array();\r\n var date = new Date();\r\n console.log('array.__proto__===Array.prototype:'+(array.__proto__===Array.prototype)); \/\/true\r\n console.log('Array.__proto__===Function.prototype:'+(Array.__proto__===Function.prototype)); \/\/true\r\n console.log('date.__proto__===Date.prototype:'+(date.__proto__===Date.prototype)); \/\/true\r\n console.log('Date.__proto__===Function.prototype:'+(Date.__proto__===Function.prototype)); \/\/true<\/pre>\n<p>Function\u3001Object\u3001Prototype\u3001__proto__\u5185\u5b58\u5173\u7cfb\u56fe<\/p>\n<a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8164530.png\"><figure class=\"mdx-lazyload-container\" style=\"max-width:631px\"><div style=\"padding-top:101.90174326466%\"><\/div><div class=\"mdx-img-loading-sp mdui-valign\"><div><div class=\"mdui-spinner\"><\/div><\/div><\/div><img width=\"631\" height=\"643\" class=\"alignnone size-full wp-image-4194 lazyload\" title=\"8164530\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8164530.png\" alt=\"8164530\" data-srcset=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8164530.png 631w, https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8164530-294x300.png 294w, https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8164530-624x635.png 624w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\"><\/figure><\/a>\n<p><span style=\"color: #000000;\">\u4e0a\u9762\u7684\u5185\u5b58\u56fe\u8ddf\u5806\u6808\u7ed3\u6784\u53ef\u4ee5\u53c2\u7167\u6587\u7ae0<\/span><a style=\"color: #1d58d1;\" href=\"http:\/\/www.cnblogs.com\/fool\/archive\/2010\/10\/07\/1845226.html\">Javascript_01_\u7406\u89e3\u5185\u5b58\u5206\u914d<\/a><span style=\"color: #000000;\">\u3002<\/span><br style=\"color: #000000;\" \/><span style=\"color: #000000;\">\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color: #000000;\">\u5806\u533a\u56fe\u8bf4\u660e\uff1a<\/span><\/p>\n<a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/35166462.png\"><figure class=\"mdx-lazyload-container\" style=\"max-width:353px\"><div style=\"padding-top:67.1388101983%\"><\/div><div class=\"mdx-img-loading-sp mdui-valign\"><div><div class=\"mdui-spinner\"><\/div><\/div><\/div><img width=\"353\" height=\"237\" class=\"alignnone size-full wp-image-4195 lazyload\" title=\"35166462\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/35166462.png\" alt=\"35166462\" data-srcset=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/35166462.png 353w, https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/35166462-300x201.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\"><\/figure><\/a>\n<div style=\"color: #000000;\">Function.prototype\u51fd\u6570\u5bf9\u8c61\u56fe\u5185\u90e8\u8868\u793aprototype\u5c5e\u6027\u7684\u7ea2\u8272\u865a\u6846\uff0c\u53ea\u662f\u4e3a\u4e86\u8bf4\u660e\u8fd9\u4e2a\u5c5e\u6027\u4e0d\u5b58\u5728\u3002<\/div>\n<div style=\"color: #000000;\">\n<div>\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0<strong>\u901a\u8fc7\u4e0a\u56feFunction\u3001Object\u3001Prototype\u5173\u7cfb\u56fe\u4e2d\uff0c\u53ef\u4ee5\u5f97\u51fa\u4e00\u4e0b\u51e0\u70b9\uff1a<\/strong><\/div>\n<div>\n<ol>\n<li>\u6240\u6709\u5bf9\u8c61\u6240\u6709\u5bf9\u8c61\uff0c\u5305\u62ec\u51fd\u6570\u5bf9\u8c61\u7684\u539f\u578b\u94fe\u6700\u7ec8\u90fd\u6307\u5411\u4e86Object.prototype\uff0c\u800cObject.prototype.__proto__===null\uff0c\u539f\u578b\u94fe\u81f3\u6b64\u7ed3\u675f\u3002<\/li>\n<li>Animal.prototype\u662f\u4e00\u4e2a\u666e\u901a\u5bf9\u8c61\u3002<\/li>\n<li>Object\u662f\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\uff0c\u4e5f\u662fFunction\u6784\u9020\u7684\uff0cObject.prototype\u662f\u4e00\u4e2a\u666e\u901a\u5bf9\u8c61\u3002<\/li>\n<li>Object.prototype.__type__\u6307\u5411null\u3002<\/li>\n<li>Function.prototype\u662f\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\uff0c\u524d\u9762\u8bf4\u51fd\u6570\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u663e\u793a\u7684prototype\u5c5e\u6027\uff0c\u4f46\u662fFunction.prototype\u5374\u6ca1\u6709prototype\u5c5e\u6027\uff0c\u5373Function.prototype.prototype===undefined\uff0c\u6240\u6709Function.prototype\u51fd\u6570\u5bf9\u8c61\u662f\u4e00\u4e2a\u7279\u4f8b\uff0c\u6ca1\u6709prototype\u5c5e\u6027\u3002<\/li>\n<li>Object\u867d\u662fFunction\u6784\u9020\u7684\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\uff0c\u4f46\u662fObject.prototype\u6ca1\u6709\u6307\u5411Function.prototype\uff0c\u5373Object.prototype!==Function.prototype\u3002<\/li>\n<\/ol>\n<\/div>\n<p><strong><br \/>\n\u4e8c \u00a0 \u00a0Prototype\u8ddfConstructor\u5173\u7cfb<\/strong><strong>\u4ecb\u7ecd<\/strong><\/p>\n<div>\u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u5728 JavaScript \u4e2d\uff0c\u6bcf\u4e2a\u51fd\u6570\u5bf9\u8c61\u90fd\u6709\u540d\u4e3a\u201cprototype\u201d\u7684\u5c5e\u6027(\u4e0a\u9762\u63d0\u5230\u8fc7Function.prototype\u51fd\u6570\u5bf9\u8c61\u662f\u4e2a\u4f8b\u5916\uff0c\u6ca1\u6709prototype\u5c5e\u6027)\uff0c\u7528\u4e8e\u5f15\u7528\u539f\u578b\u5bf9\u8c61\u3002\u6b64\u539f\u578b\u5bf9\u8c61\u53c8\u6709\u540d\u4e3a\u201cconstructor\u201d\u7684\u5c5e\u6027\uff0c\u5b83\u53cd\u8fc7\u6765\u5f15\u7528\u51fd\u6570\u672c\u8eab\u3002\u8fd9\u662f\u4e00\u79cd\u5faa\u73af\u5f15\u7528\uff08i.e.\u00a0Animal.prototype.constructor===Animal\uff09\u3002<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u901a\u8fc7\u4ee5\u4e0b\u4f8b\u5b50\u8ddf\u5185\u5b58\u6548\u679c\u56fe\u6765\u5206\u6790Prototype\u3001constructor\u95f4\u7684\u5173\u7cfb\u3002<\/div>\n<\/div>\n<pre>console.log('**************constructor****************');\r\nconsole.log('anim.constructor===Animal:'+(anim.constructor===Animal)) ; \/\/true\r\n console.log('Animal===Animal.prototype.constructor:'+(Animal===Animal.prototype.constructor)) ; \/\/true\r\n console.log('Animal.constructor===Function.prototype.constructor:'+(Animal.constructor===Function.prototype.constructor)); \/\/true\r\n console.log('Function.prototype.constructor===Function:'+(Function.prototype.constructor===Function)); \/\/true\r\n console.log('Function.constructor===Function.prototype.constructor:'+(Function.constructor===Function.prototype.constructor)); \/\/true\r\nconsole.log('Object.prototype.constructor===Object:'+(Object.prototype.constructor===Object)); \/\/true\r\n console.log('Object.constructor====Function:'+(Object.constructor===Function)); \/\/true<\/pre>\n<p><strong style=\"color: #000000;\"><span data-wiz-span=\"data-wiz-span\">\u00a0prototype\u3001constructor\u5185\u5b58\u5173\u7cfb\u56fe(<\/span>\u5728Function\u3001Object\u3001Prototype\u5173\u7cfb\u56fe\u4e0a\u52a0\u5165constructor\u5143\u7d20)\uff1a<\/strong><\/p>\n<a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8199006.png\"><figure class=\"mdx-lazyload-container\" style=\"max-width:627px\"><div style=\"padding-top:103.0303030303%\"><\/div><div class=\"mdx-img-loading-sp mdui-valign\"><div><div class=\"mdui-spinner\"><\/div><\/div><\/div><img width=\"627\" height=\"646\" class=\"alignnone size-full wp-image-4196 lazyload\" title=\"8199006\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8199006.png\" alt=\"8199006\" data-srcset=\"https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8199006.png 627w, https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8199006-291x300.png 291w, https:\/\/sdeno.com\/wp-content\/uploads\/2015\/10\/8199006-624x642.png 624w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\"><\/figure><\/a>\n<div style=\"color: #000000;\">\u4e0a\u56fe\u4e2d\uff0c\u7ea2\u8272\u7bad\u5934\u8868\u793a\u51fd\u6570\u5bf9\u8c61\u7684\u539f\u578b\u7684constructor\u6240\u6307\u5411\u7684\u5bf9\u8c61\u3002<\/div>\n<div style=\"color: #000000;\">\n<div>\n<ol>\n<li>\u6ce8\u610fObject.constructor===Function\uff1b\u672c\u8eabObject\u5c31\u662fFunction\u51fd\u6570\u6784\u9020\u51fa\u6765\u7684<\/li>\n<li>\u5982\u4f55\u67e5\u627e\u4e00\u4e2a\u5bf9\u8c61\u7684constructor\uff0c\u5c31\u662f\u5728\u8be5\u5bf9\u8c61\u7684\u539f\u578b\u94fe\u4e0a\u5bfb\u627e\u78b0\u5230\u7684\u7b2c\u4e00\u4e2aconstructor\u5c5e\u6027\u6240\u6307\u5411\u7684\u5bf9\u8c61\u3002<\/li>\n<\/ol>\n<\/div>\n<div><\/div>\n<div><strong>\u53c2\u8003\uff1a<\/strong><\/div>\n<div><a style=\"color: #1d58d1;\" href=\"http:\/\/www.cnblogs.com\/fool\/category\/264215.html\">http:\/\/www.cnblogs.com\/fool\/category\/264215.html<\/a>\u00a0(javascript\u539f\u7406\u4ecb\u7ecd)<\/div>\n<div><a style=\"color: #1d58d1;\" href=\"http:\/\/www.libuchao.com\/2012\/05\/14\/prototypes-in-javascript\/\">http:\/\/www.libuchao.com\/2012\/05\/14\/prototypes-in-javascript\/<\/a>\u00a0(JavaScript \u7684\u539f\u578b\u5bf9\u8c61 Prototype)<\/div>\n<div><a style=\"color: #1d58d1;\" href=\"http:\/\/rockyuse.iteye.com\/blog\/1426510\">http:\/\/rockyuse.iteye.com\/blog\/1426510<\/a>\u00a0(\u7406\u89e3js\u4e2d\u7684\u539f\u578b\u94fe\uff0cprototype\u4e0e__proto__\u7684\u5173\u7cfb)<\/div>\n<div><\/div>\n<div>\u6587\u7ae0\u6765\u6e90\uff1a<a href=\"http:\/\/www.blogjava.net\/heavensay\/archive\/2013\/10\/20\/405440.html\" target=\"_blank\">http:\/\/www.blogjava.net\/heavensay\/archive\/2013\/10\/20\/405440.html<\/a><\/div>\n<div><\/div>\n<div><a href=\"https:\/\/sdeno.com\/?p=3062\" target=\"_blank\">\u6784\u9020\u51fd\u6570\u3001\u539f\u578b\u51fd\u6570\u548c\u539f\u578b\u94fe\u7684\u5173\u7cfb<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Function\u3001Object\uff1aJs\u81ea\u5e26\u7684\u51fd\u6570\u5bf9\u8c61\u3002 prototype,\u6bcf\u4e00\u4e2a\u51fd\u6570\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u663e\u793a\u7684prot [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-4193","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4193"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4193\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}