{"id":5471,"date":"2018-07-07T15:17:43","date_gmt":"2018-07-07T06:17:43","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=5471"},"modified":"2023-05-27T21:01:56","modified_gmt":"2023-05-27T12:01:56","slug":"%e3%80%90javascript%e3%80%91%e3%80%8c%e3%82%b3%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%bf%e3%80%8d%e3%81%ae%e5%95%8f%e9%a1%8c%e7%82%b9","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=5471","title":{"rendered":"\u3010JavaScript\u3011\u300cprototype\u300d\u3001\u300c__proto__\u300d\u3001\u300c\u30ea\u30c6\u30e9\u30eb\u8868\u73fe\u300d\u3001\u300c\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u30c1\u30a7\u30fc\u30f3\u300d"},"content":{"rendered":"<p>JavaScript\u3067\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30e1\u30f3\u30d0\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306b\u3001<span style=\"color: #ff0000;\"><strong>prototype<\/strong><\/span>\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>prototype\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u7279\u5fb4<\/h2>\n<ul>\n<li>prototype\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u683c\u7d0d\u3055\u308c\u305f\u30e1\u30f3\u30d0\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u305f\u5148\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5f15\u304d\u7d99\u304c\u308b\u3002<\/li>\n<li>\u3042\u304f\u307e\u3067\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5229\u7528\u3055\u308c\u308b\u306e\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u5024\u306e\u53c2\u7167\u6642\u306e\u307f\u3067\u3001\u8a2d\u5b9a\u6642\u306f\u4f7f\u7528\u3055\u308c\u306a\u3044\u3002<\/strong><\/span><\/li>\n<\/ul>\n<h2>prototype\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u30e1\u30ea\u30c3\u30c8<\/h2>\n<h3>\u7121\u99c4\u306a\u30e1\u30e2\u30ea\u4f7f\u7528\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u70b9<\/h3>\n<p>\u306a\u306e\u3067\u3001\u3042\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u305f\u3068\u3057\u3066\u3082\u3001prototype\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u8ffd\u52a0\u3057\u305f\u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308c\u3070\u3001<span style=\"color: #ff0000;\"><strong>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u3066\u3082\u7121\u99c4\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u751f\u6210\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u306e\u3067\u3001\u7121\u99c4\u306a\u30e1\u30e2\u30ea\u6d88\u8cbb\u304b\u3089\u89e3\u653e<\/strong><\/span>\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u3042\u304f\u307e\u3067<span style=\"color: #ff0000;\"><strong>\u300c\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u6697\u9ed9\u7684\u306b\u53c2\u7167\u3055\u308c\u308b\u3060\u3051\u300d\u3067\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30b3\u30d4\u30fc\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/span><\/p>\n<h3>\u30e1\u30f3\u30d0\u306e\u8ffd\u52a0\u3001\u5909\u66f4\u3092\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304c\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306b\u8a8d\u8b58\u3067\u304d\u308b\u70b9<\/h3>\n<p>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u30e1\u30f3\u30d0\u3092\u30b3\u30d4\u30fc\u3057\u306a\u3044\u306e\u3067\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u5909\u66f4\u3092\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5074\u3067\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306b\u78ba\u8a8d\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001new\u3067\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3057\u305f\u5f8c\u306b\u3001\u5143\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u30e1\u30f3\u30d0\u306e\u5909\u66f4\u304c\u3042\u3063\u305f\u5834\u5408\u3082\u3001\u751f\u6210\u3055\u308c\u305f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3089\u3082\u305d\u306e\u5909\u66f4\u3092\u30ad\u30e3\u30c3\u30c1\u30a2\u30c3\u30d7\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30c7\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u3057\u304b\u3057\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30c7\u30e1\u30ea\u30c3\u30c8\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30b3\u30fc\u30c9\u304c\u5197\u9577\u306b\u306a\u308b\u3002<\/h3>\n<p>\u3044\u3061\u3044\u3061\u4e0b\u8a18\u306e\u3088\u3046\u306b\u30e1\u30f3\u30d0\u3092\u8ffd\u52a0\u3059\u308b\u306e\u306f\u9762\u5012\u3067\u3059\u3057\u3001\u30e1\u30f3\u30d0\u306e\u6570\u304c\u591a\u304f\u306a\u3063\u3066\u304f\u308b\u3068\u5197\u9577\u306b\u306a\u3063\u3066\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d.prototype.\u30e1\u30f3\u30d0\u540d<\/pre>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d\u304c\u5909\u66f4\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u306f\u3001\u5168\u3066\u306e\u5b9a\u7fa9\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d\u3092\u5909\u3048\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<h3>\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u306b\u554f\u984c\u304c\u51fa\u3066\u304f\u308b\u3002<\/h3>\n<p>\u3069\u3053\u304b\u3089\u3069\u3053\u307e\u3067\u304c\u3001\u540c\u3058\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30f3\u30d0\u3067\u3042\u308b\u306e\u304b\u898b\u3048\u306b\u304f\u304f\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u51fa\u3066\u304f\u308b\u306e\u304c\u3001<span style=\"color: #ff0000;\"><strong>\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30c6\u30e9\u30eb\u8868\u73fe\u300d<\/strong><\/span>\u3068\u3044\u3046\u8a18\u8ff0\u65b9\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u4ed5\u7d44\u307f<\/h2>\n<p>JavaScript\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u5168\u3066\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u300c\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u300d\u3092\u30d9\u30fc\u30b9\u306b\u3057\u3066\u4f5c\u3089\u308c\u307e\u3059\u3002\u5168\u3066\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306fPrototype\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4fdd\u6301\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">const obj = {\r\n a: \"aaa\",\r\n b: 12,\r\n [[Prototype]]: \u30aa\u30d6\u30b8\u30a7\u30af\u30c8 or null\r\n}<\/pre>\n<p>\u305d\u308c\uff08\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\uff09\u3092\u30b3\u30d4\u30fc\u3057\u3066\u65b0\u3057\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3067\u8a18\u8ff0\u3059\u308b\u3068\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u300c\u30b3\u30d4\u30fc\u300d\u304c\u4f5c\u3089\u308c\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u300c\u53c2\u7167\u300d\u3057\u3066\u5229\u7528\u3055\u308c\u307e\u3059\u3002\u306a\u305c\u306a\u3089\u3001<span style=\"color: #ff0000;\"><strong>\u57fa\u672c\u7684\u306b\u30e1\u30bd\u30c3\u30c9\u306f\u3069\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5148\u3067\u3082\u5185\u5bb9\u306f\u540c\u3058\u306a\u306e\u3067\u8907\u88fd\u3057\u3066\u4f5c\u308b\u306e\u306f\u30e1\u30e2\u30ea\u306e\u7121\u99c4\u306b\u306a\u308b\u305f\u3081<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<h2>\u5b9a\u7fa9\u65b9\u6cd5<\/h2>\n<pre class=\"lang:default decode:true\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d.prototype.\u30e1\u30bd\u30c3\u30c9\u540d = function() {}<\/pre>\n<h2>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u8a2d\u5b9a<\/h2>\n<h3>Object.setPrototypeOf\u3092\u4f7f\u3046<\/h3>\n<p>2015\u5e74\u306b\u5b9f\u88c5\u3055\u308c\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true\">const obj = {key:\"\u3042\u3042\u3042\"}\r\nObject.setPrototypeOf(obj,{key2:\"\u3044\u3044\u3044\"});<\/pre>\n<h3>\u30bb\u30c3\u30bf\u30fc\u300c__proto__\u300d\u3092\u4f7f\u3046<\/h3>\n<p>\u300c__proto__\u300d\u3068\u306f\u4ee5\u4e0b\u3069\u3061\u3089\u304b\u306e\u69cb\u6587\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u305f\u969b\u306b\u88cf\u5074\u3067\u4f5c\u3089\u308c\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u3059\u3002\u5168\u3066\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3053\u306e\u300c__proto__\u300d\u3092\u4fdd\u6301\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h4>\u4ed5\u7d44\u307f<\/h4>\n<p>\u3042\u304f\u307e\u3067Prototype\u3092\u8fd4\u3057\u3066\u304f\u308c\u308b\u30b2\u30c3\u30bf\u30fc\u306b\u904e\u304e\u307e\u305b\u3093\u3002\u76f4\u63a5\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u8868\u793a\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3067\u3059\u3002\u30b2\u30c3\u30bf\u30fc\u306a\u306e\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6307\u5b9a\u3059\u308c\u3070\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const obj = {a:1};\r\nobj.__proto__; \/\/ \u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u304c\u8fd4\u308b\u3002<\/pre>\n<p>\u307e\u305f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u3048\u3070\u30bb\u30c3\u30bf\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const obj = {key:\"\u3042\u3042\u3042\"}\r\nobj.__proto__ = {key2:\"\u3044\u3044\u3044\"};<\/pre>\n<h4>\u57fa\u672c\u306f\u4f7f\u308f\u306a\u3044\u3053\u3068<\/h4>\n<p>\u4eca\u306f\u975e\u63a8\u5968\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee3\u308f\u308a\u306b2012\u5e74\u306b\u767b\u5834\u3057\u305fObject.create\u3068\u3044\u3046\u6587\u6cd5\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305f\u30012015\u5e74\u4ee5\u964d\u306b\u767b\u5834\u3057\u305f\u4ee5\u4e0b\u306e\u6587\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002\uff08\u305f\u3060\u3001\u57fa\u672c\u7684\u306b\u4e00\u5ea6\u751f\u6210\u3057\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u3044\u3058\u308b\u306e\u306f\u3057\u306a\u3044\u306e\u3067Object.create\u3060\u3051\u5b9f\u52d9\u3067\u306f\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff09<\/p>\n<ul>\n<li>Object.setPrototypeOf<\/li>\n<li>Object.getPrototypeOf<\/li>\n<\/ul>\n<h4>\u306a\u305c__proto__\u306f\u975e\u63a8\u5968\u306b\u306a\u3063\u305f\u306e\u304b\uff1f<\/h4>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306f\u4e88\u7d04\u8a9e\u3068\u304b\u3069\u3093\u306a\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u3067\u3082\u3088\u304b\u3063\u305f\u3002\u3057\u304b\u3057\u3001__proto__\u3092\u6307\u5b9a\u3057\u305f\u6642\u3060\u3051\u306f\u4f8b\u3048\u3070string\u3092\u5165\u308c\u3088\u3046\u3068\u3057\u305f\u969b\u306f\u4e0a\u66f8\u304d\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3067\u3059\u3002\u3053\u306e\u52d5\u304d\u304c\u3084\u3084\u3053\u3057\u3044\u305f\u3081\u3042\u304f\u307e\u3067\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u3044\u3058\u308b\u3068\u304d\u306f\u30e1\u30bd\u30c3\u30c9\u7d4c\u7531\u306b\u3057\u307e\u3057\u3087\u3046\u3068\u306a\u3063\u305f\u308f\u3051\u3067\u3059\u3002<\/p>\n<h3>Object.create\u3092\u4f7f\u3046<\/h3>\n<p>2012\u5e74\u306b\u5b9f\u88c5\u3055\u308c\u305f\u3002<\/p>\n<p>\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u308c\u3068\u540c\u6642\u306b\u7a7a\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">const obj = Object.create({key3:\"\u3046\u3046\u3046\"}); \/\/ \u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u5185\u5bb9\r\nobj.name = \"\u592a\u90ce\"; \/\/\u3053\u308c\u304c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5185\u5bb9<\/pre>\n<p>\u57fa\u672c\u7684\u306b\u4e00\u5ea6\u751f\u6210\u3057\u305f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u3044\u3058\u308b\u306e\u306f\u3057\u306a\u3044\u306e\u3067setPrototypeOf\u306f\u4f7f\u308f\u305a\u3001Object.create\u3060\u3051\u5b9f\u52d9\u3067\u306f\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u78ba\u8a8d\u65b9\u6cd5<\/h2>\n<h3>Object.getPrototypeOf\u3092\u4f7f\u3046<\/h3>\n<p>2015\u5e74\u306b\u5b9f\u88c5\u3055\u308c\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true\">const obj = {key:\"\u3042\u3042\u3042\"}\r\nObject.getPrototypeOf(obj);<\/pre>\n<h3>\u30b2\u30c3\u30bf\u30fc\u300c__proto__\u300d\u3092\u4f7f\u3046<\/h3>\n<p>\u53e4\u304f\u304b\u3089\u3042\u308b\u3002\u975e\u63a8\u5968\u306b\u306a\u3063\u305f\u3002<\/p>\n<pre class=\"lang:default decode:true\">const obj = {key:\"\u3042\u3042\u3042\"}\r\nobj__proto__;<\/pre>\n<h2>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u524d\u63d0\u3068\u306a\u3063\u3066\u3044\u308b\u69cb\u6587<\/h2>\n<h3>for in\u30eb\u30fc\u30d7<\/h3>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ad\u30fc\u3092\u30eb\u30fc\u30d7\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308bES6\u304b\u3089\u306e\u69cb\u6587\u3067\u3059\u304c\u3001\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3082\u542b\u3081\u3066\u30eb\u30fc\u30d7\u3092\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u5b9f\u969b\u306f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u307e\u3067\u30eb\u30fc\u30d7\u3057\u3066\u6b32\u3057\u304f\u306a\u3044\u30b1\u30fc\u30b9\u306e\u65b9\u304c\u591a\u3044\u306e\u3067\u3082\u3057\u30eb\u30fc\u30d7\u3055\u305b\u308b\u5834\u5408\u306ffor of \u3068Object.keys\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u30eb\u30fc\u30d7\u3055\u305b\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h3>\u305d\u306e\u4ed6\u69cb\u6587<\/h3>\n<p>\u57fa\u672c\u7684\u306b\u3001for in\u4ee5\u5916\u306f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u307e\u3067\u9061\u3063\u3066\u53c2\u7167\u3057\u3066\u304f\u308c\u307e\u305b\u3093\u3002<\/p>\n<ul>\n<li>Object.entries<\/li>\n<li>Object.getOwnPropertyNames<\/li>\n<li>for of Object.keys<\/li>\n<\/ul>\n<p>\u3061\u306a\u307f\u306b\u300cOwn\u300d\u3068\u3044\u3046\u5358\u8a9e\u306f\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u307e\u3067\u898b\u306a\u3044\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30c6\u30e9\u30eb\u8868\u73fe<\/h2>\n<h3>\u69cb\u6587<\/h3>\n<pre class=\"lang:default decode:true\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d.prototype ={\r\n  \u30e1\u30bd\u30c3\u30c9\u540d1: function(){\r\n    return \u623b\u308a\u5024;\r\n  },\r\n  \u30e1\u30bd\u30c3\u30c9\u540d2: function(){\r\n    return \u623b\u308a\u5024;\r\n  }\r\n}<\/pre>\n<h3>\u30e1\u30ea\u30c3\u30c8<\/h3>\n<ul>\n<li>\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d.prototype.\u30e1\u30bd\u30c3\u30c9\u540d\u300d\u3068\u3044\u3046\u8a18\u8ff0\u65b9\u6cd5\u3092\u6291\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/li>\n<li>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u5834\u5408\u3067\u3082\u3001\u5909\u66f4\u7b87\u6240\u3092\u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/li>\n<li>\u540c\u4e00\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30f3\u30d0\u304c1\u30d6\u30ed\u30c3\u30af\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u304c\u4e0a\u304c\u308b\u3002<\/li>\n<\/ul>\n<h2>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u30c1\u30a7\u30fc\u30f3\u3068\u306f\uff1f<\/h2>\n<p>JavaScript\u306e\u4e16\u754c\u306b\u304a\u3051\u308b<span style=\"color: #ff0000;\"><strong>\u7d99\u627f\u306e\u4ed5\u7d44\u307f\u306e\u3053\u3068<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<p>JavaScript\u3067\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u540c\u58eb\u3092\u300c\u6697\u9ed9\u306e\u53c2\u7167\u300d\u3067\u9023\u7d50\u3057\u3066\u3001\u4e92\u3044\u306b\u7d99\u627f\u95a2\u4fc2\u3092\u6301\u305f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b<\/strong><\/span>\u306e\u3067\u3059\u3002<\/p>\n<h3>\u4ed5\u7d44\u307f<\/h3>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u6307\u5b9a\u3055\u308c\u305f\u30ad\u30fc\u306fPrototype\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u6307\u5b9a\u3055\u308c\u305f\u5148\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u307e\u3067\u30ad\u30fc\u304c\u306a\u3044\u304b\u3092\u8abf\u3079\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">const obj = {\r\n a: \"aaa\",\r\n b: 12,\r\n [[Prototype]]: obj2\r\n}\r\n\r\nconst obj2 = {\r\n c: \"aaa\",\r\n [[Prototype]]: obj3\r\n}\r\n\r\nconst obj3 = {\r\n d: \"aaa\",\r\n [[Prototype]]: null\r\n}\r\n\r\nobj.d \/\/ aaa\u304c\u8fd4\u308b\u3002\r\nobj.c = 5; \/\/ obj2\u306e\u5024\u304c\u66f8\u304d\u5909\u308f\u308b\u306e\u3067\u306f\u306a\u304f\u3001obj\u306b\u65b0\u3057\u304fc\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u8ffd\u52a0\u3055\u308c\u308b\u3002<\/pre>\n<p>\u65b0\u3057\u304f\u30ad\u30fc\u3092\u8ffd\u52a0\u3059\u308b\u3068\u304d\u306f\u4e00\u756a\u53c2\u7167\u5148\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5024\u304c\u66f8\u304d\u5909\u308f\u308b\u306e\u3067\u306f\u306a\u304f\u5143\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30ad\u30fc\u304c\u8ffd\u52a0\u3055\u308c\u308b\u306e\u3067\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<h4>this\u306e\u6271\u3044<\/h4>\n<p>obj3\u306e\u95a2\u6570\u3067\u4eee\u306bthis\u3092\u4f7f\u3063\u305f\u5834\u5408\u306f\u5148\u982d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308b\u300cobj\u300d\u304c\u8fd4\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">const obj = {\r\n a: \"aaa\",\r\n b: 12,\r\n [[Prototype]]: obj2\r\n}\r\n\r\nconst obj2 = {\r\n c: \"aaa\",\r\n [[Prototype]]: obj3\r\n}\r\n\r\nconst obj3 = {\r\n d: \"aaa\",\r\n getThis() { return this } \/\/ \u3053\u306e\u4e2d\u306b\u306fobj\u304c\u5165\u308b\u3002\r\n [[Prototype]]: null\r\n}\r\n\r\nobj.d \/\/ aaa\u304c\u8fd4\u308b\u3002<\/pre>\n<h3>\u69cb\u6587<\/h3>\n<pre class=\"lang:default decode:true \">\u5b50\u30aa\u30d6\u30b8\u30a7\u30af\u30c8.prototype = new \u89aa\u30aa\u30d6\u30b8\u30a7\u30af\u30c8();<\/pre>\n<p>\u4e0a\u8a18\u306e\u69cb\u6587\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u5b50\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092new\u3057\u305f\u969b\u306b\u3001<span style=\"color: #ff0000;\"><strong>\u89aa\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u3082\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b<\/strong><\/span>\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>JavaScript\u306e\u7d99\u627f\u306f\u52d5\u7684\u306a\u3082\u306e<\/h3>\n<p>Java\u7b49\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u306e\u7d99\u627f\u3067\u3042\u308c\u3070\u3001\u9759\u7684\u306a\u3082\u306e\u3067\u3001\u4e00\u5ea6\u7d99\u627f\u95a2\u4fc2\u3092\u7bc9\u3044\u305f\u5834\u5408\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e2d\u3067\u305d\u306e\u95a2\u4fc2\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001JavaScript\u3067\u306f\u3001<span style=\"color: #ff0000;\"><strong>\u52d5\u7684\u306b\u7d99\u627f\u95a2\u4fc2\u3059\u3089\u3082\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/strong><\/span>\u305d\u306e\u8fba\u304c\u8981\u6ce8\u610f\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"JavaScript\u3067\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30e1\u30f3\u30d0\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306b\u3001prototype\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002 prototype\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u7279\u5fb4 prototype\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u683c\u7d0d\u3055\u308c\u305f\u30e1\u30f3\u30d0\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u305f [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5471"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5471"}],"version-history":[{"count":15,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5471\/revisions"}],"predecessor-version":[{"id":20302,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/5471\/revisions\/20302"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5471"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}