<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://mochiu.net/index.php?action=history&amp;feed=atom&amp;title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97</id>
	<title>JavaScriptの基礎 - 継承とプロトタイプ - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://mochiu.net/index.php?action=history&amp;feed=atom&amp;title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97"/>
	<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;action=history"/>
	<updated>2026-07-10T01:37:52Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14361&amp;oldid=prev</id>
		<title>Wiki: /* classとプロトタイプの関係 */</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14361&amp;oldid=prev"/>
		<updated>2026-02-19T19:44:53Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;classとプロトタイプの関係&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年2月20日 (金) 04:44時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l251&quot;&gt;251行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;251行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;! class構文 !! プロトタイプベースの等価コード !! 説明&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;! class構文 !! プロトタイプベースの等価コード !! 説明&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;class Animal {}&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;function Animal() {}&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;クラス宣言はコンストラクタ関数に対応する&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| class Animal {} || function Animal() {} || &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;クラス宣言はコンストラクタ関数に対応する。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;constructor(name) { this.name = name; }&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;function Animal(name) { this.name = name; }&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;コンストラクタ本体はそのまま関数本体になる&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| constructor(name) { this.name = name; } || function Animal(name) { this.name = name; } || &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;コンストラクタ本体はそのまま関数本体になる。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;speak() { ... }&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;Animal.prototype.speak = function() { ... };&amp;lt;/u&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| インスタンスメソッドはprototypeに追加される&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| speak() { ... } || Animal.prototype.speak = function() { ... }; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| インスタンスメソッドは &amp;lt;u&amp;gt;prototype&lt;/ins&gt;&amp;lt;/u&amp;gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;に追加される。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;static create() { ... }&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;Animal.create = function() { ... };&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;静的メソッドはコンストラクタ関数自体のプロパティになる&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| static create() { ... } || Animal.create = function() { ... }; || &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;静的メソッドはコンストラクタ関数自体のプロパティになる。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;class Dog extends Animal&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;Object.setPrototypeOf(Dog.prototype, Animal.prototype);&amp;lt;/u&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| extendsはプロトタイプチェーンを設定する&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| class Dog extends Animal || Object.setPrototypeOf(Dog.prototype, Animal.prototype); &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| &amp;lt;u&amp;gt;extends&lt;/ins&gt;&amp;lt;/u&amp;gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;はプロトタイプチェーンを設定する。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;super(name)&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;Animal.call(this, name);&amp;lt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;/&lt;/del&gt;u&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| &lt;/del&gt;super()&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;は親コンストラクタをthisに対して呼び出す&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| super(name) || Animal.call(this, name); &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| &lt;/ins&gt;&amp;lt;u&amp;gt;super()&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; は親コンストラクタを &amp;lt;u&amp;gt;this&amp;lt;/u&amp;gt; に対して呼び出す。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;super.speak()&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; &lt;/del&gt;|| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;u&amp;gt;&lt;/del&gt;Animal.prototype.speak.call(this);&amp;lt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;/&lt;/del&gt;u&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| &lt;/del&gt;super.method()&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;は親のprototypeのメソッドを呼び出す&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| super.speak() || Animal.prototype.speak.call(this); &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|| &lt;/ins&gt;&amp;lt;u&amp;gt;super.method()&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/u&amp;gt; は親の &amp;lt;u&amp;gt;prototype&amp;lt;/u&amp;gt; のメソッドを呼び出す。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/center&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/center&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mochiu_wiki:diff:1.41:old-14360:rev-14361:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
	<entry>
		<id>https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14360&amp;oldid=prev</id>
		<title>Wiki: /* プロトタイプチェーンの仕組み */</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14360&amp;oldid=prev"/>
		<updated>2026-02-19T19:42:50Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;プロトタイプチェーンの仕組み&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年2月20日 (金) 04:42時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l169&quot;&gt;169行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;169行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# オブジェクト自身のプロパティを探索する。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# オブジェクト自身のプロパティを探索する。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# 見つからない場合、&amp;lt;code&amp;gt;[[Prototype]]&amp;lt;/code&amp;gt; (プロトタイプ) のプロパティを探索する。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# 見つからない場合、&amp;lt;code&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;gt;&amp;lt;nowiki&lt;/ins&gt;&amp;gt;[[Prototype]]&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/nowiki&amp;gt;&lt;/ins&gt;&amp;lt;/code&amp;gt; (プロトタイプ) のプロパティを探索する。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# 見つからない場合、プロトタイプのプロトタイプを探索する。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# 見つからない場合、プロトタイプのプロトタイプを探索する。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; に到達しても見つからない場合、&amp;lt;u&amp;gt;undefined&amp;lt;/u&amp;gt; を返す。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; に到達しても見つからない場合、&amp;lt;u&amp;gt;undefined&amp;lt;/u&amp;gt; を返す。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l203&quot;&gt;203行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;203行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== classとプロトタイプの関係 ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== classとプロトタイプの関係 ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文はシンタックスシュガーであり、内部的にはプロトタイプベースの継承を使用している。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文はシンタックスシュガーであり、内部的にはプロトタイプベースの継承を使用している。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
	<entry>
		<id>https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14359&amp;oldid=prev</id>
		<title>Wiki: /* プロトタイプの基本概念 */</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14359&amp;oldid=prev"/>
		<updated>2026-02-19T19:42:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;プロトタイプの基本概念&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年2月20日 (金) 04:42時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l137&quot;&gt;137行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;137行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== プロトタイプの基本概念 ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== プロトタイプの基本概念 ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;全てのJavaScriptオブジェクトは、内部プロパティ &amp;lt;code&amp;gt;[[Prototype]]&amp;lt;/code&amp;gt; を持つ。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;全てのJavaScriptオブジェクトは、内部プロパティ &amp;lt;code&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;gt;&amp;lt;nowiki&lt;/ins&gt;&amp;gt;[[Prototype]]&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/nowiki&amp;gt;&lt;/ins&gt;&amp;lt;/code&amp;gt; を持つ。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;この内部プロパティは、&amp;lt;code&amp;gt;Object.getPrototypeOf()&amp;lt;/code&amp;gt; を使用して取得できる。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;この内部プロパティは、&amp;lt;code&amp;gt;Object.getPrototypeOf()&amp;lt;/code&amp;gt; を使用して取得できる。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l164&quot;&gt;164行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;164行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== プロトタイプチェーンの仕組み ====&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==== プロトタイプチェーンの仕組み ====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;オブジェクトのプロパティやメソッドにアクセスすると、JavaScriptエンジンは以下の順序で探索を行う。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;オブジェクトのプロパティやメソッドにアクセスすると、JavaScriptエンジンは以下の順序で探索を行う。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
	<entry>
		<id>https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14358&amp;oldid=prev</id>
		<title>Wiki: /* 概要 */</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14358&amp;oldid=prev"/>
		<updated>2026-02-19T19:42:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;概要&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2026年2月20日 (金) 04:42時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l4&quot;&gt;4行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;4行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;これはシンタックスシュガーである。(内部では依然としてプロトタイプベースの機構が動作している)&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;これはシンタックスシュガーである。(内部では依然としてプロトタイプベースの機構が動作している)&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;プロトタイプチェーンとは、オブジェクトが持つ内部プロパティ &amp;lt;code&amp;gt;[[Prototype]]&amp;lt;/code&amp;gt; を辿ることで、プロパティやメソッドを継承元から順に探索する仕組みである。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;プロトタイプチェーンとは、オブジェクトが持つ内部プロパティ &amp;lt;code&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;gt;&amp;lt;nowiki&lt;/ins&gt;&amp;gt;[[Prototype]]&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/nowiki&amp;gt;&lt;/ins&gt;&amp;lt;/code&amp;gt; を辿ることで、プロパティやメソッドを継承元から順に探索する仕組みである。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;プロパティは、&amp;lt;u&amp;gt;自身のオブジェクト -&amp;gt; プロトタイプ -&amp;gt; プロトタイプのプロトタイプ -&amp;gt; ... -&amp;gt; null&amp;lt;/u&amp;gt; の順に探索され、見つからない場合は &amp;lt;u&amp;gt;undefined&amp;lt;/u&amp;gt; を返す。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;プロパティは、&amp;lt;u&amp;gt;自身のオブジェクト -&amp;gt; プロトタイプ -&amp;gt; プロトタイプのプロトタイプ -&amp;gt; ... -&amp;gt; null&amp;lt;/u&amp;gt; の順に探索され、見つからない場合は &amp;lt;u&amp;gt;undefined&amp;lt;/u&amp;gt; を返す。&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mochiu_wiki:diff:1.41:old-14357:rev-14358:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
	<entry>
		<id>https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14357&amp;oldid=prev</id>
		<title>Wiki: ページの作成:「== 概要 == JavaScriptはプロトタイプベースのオブジェクト指向言語であり、全ての継承はプロトタイプチェーンという仕組みによって実現されている。&lt;br&gt; ES2015で導入された &lt;code&gt;class&lt;/code&gt; 構文の &lt;code&gt;extends&lt;/code&gt; と &lt;code&gt;super&lt;/code&gt; により、他の言語に近い直感的なクラス継承を記述できるが、&lt;br&gt; これはシンタックスシュガーである。(内部では依然とし…」</title>
		<link rel="alternate" type="text/html" href="https://mochiu.net/index.php?title=JavaScript%E3%81%AE%E5%9F%BA%E7%A4%8E_-_%E7%B6%99%E6%89%BF%E3%81%A8%E3%83%97%E3%83%AD%E3%83%88%E3%82%BF%E3%82%A4%E3%83%97&amp;diff=14357&amp;oldid=prev"/>
		<updated>2026-02-19T19:42:05Z</updated>

		<summary type="html">&lt;p&gt;ページの作成:「== 概要 == JavaScriptはプロトタイプベースのオブジェクト指向言語であり、全ての継承はプロトタイプチェーンという仕組みによって実現されている。&amp;lt;br&amp;gt; ES2015で導入された &amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文の &amp;lt;code&amp;gt;extends&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;super&amp;lt;/code&amp;gt; により、他の言語に近い直感的なクラス継承を記述できるが、&amp;lt;br&amp;gt; これはシンタックスシュガーである。(内部では依然とし…」&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== 概要 ==&lt;br /&gt;
JavaScriptはプロトタイプベースのオブジェクト指向言語であり、全ての継承はプロトタイプチェーンという仕組みによって実現されている。&amp;lt;br&amp;gt;&lt;br /&gt;
ES2015で導入された &amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文の &amp;lt;code&amp;gt;extends&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;super&amp;lt;/code&amp;gt; により、他の言語に近い直感的なクラス継承を記述できるが、&amp;lt;br&amp;gt;&lt;br /&gt;
これはシンタックスシュガーである。(内部では依然としてプロトタイプベースの機構が動作している)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
プロトタイプチェーンとは、オブジェクトが持つ内部プロパティ &amp;lt;code&amp;gt;[[Prototype]]&amp;lt;/code&amp;gt; を辿ることで、プロパティやメソッドを継承元から順に探索する仕組みである。&amp;lt;br&amp;gt;&lt;br /&gt;
プロパティは、&amp;lt;u&amp;gt;自身のオブジェクト -&amp;gt; プロトタイプ -&amp;gt; プロトタイプのプロトタイプ -&amp;gt; ... -&amp;gt; null&amp;lt;/u&amp;gt; の順に探索され、見つからない場合は &amp;lt;u&amp;gt;undefined&amp;lt;/u&amp;gt; を返す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
型チェックには &amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;typeof&amp;lt;/code&amp;gt; の2つの演算子を使い分ける。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;typeof&amp;lt;/code&amp;gt; はプリミティブ型の判定に用い、&amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; はプロトタイプチェーンを辿ってオブジェクトの型 (コンストラクタ) を検査する。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;なお、&amp;lt;code&amp;gt;typeof null === &amp;quot;object&amp;quot;&amp;lt;/code&amp;gt; となる点は言語仕様上の既知の問題であり、注意が必要である。&amp;lt;/u&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
ReactのErrorBoundaryは、クラス継承が今なお必須とされる代表的な実用例である。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;getDerivedStateFromError&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;componentDidCatch&amp;lt;/code&amp;gt; はクラスコンポーネント専用のライフサイクルメソッドであり、現時点ではHooksに相当する代替手段が存在しない。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
クラスの宣言、コンストラクタ、メソッド、フィールド、静的メンバーについては、[[JavaScriptの基礎 - クラス]]のページを参照すること。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== クラスの継承 ==&lt;br /&gt;
&amp;lt;code&amp;gt;extends&amp;lt;/code&amp;gt; キーワードを使用することにより、既存のクラスを継承した新しいクラスを定義できる。&amp;lt;br&amp;gt;&lt;br /&gt;
子クラスは親クラスのプロパティとメソッドを全て引き継ぎ、独自のメンバーを追加または上書きすることができる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== extendsキーワード ====&lt;br /&gt;
&amp;lt;u&amp;gt;class Child extends Parent {}&amp;lt;/u&amp;gt; と記述することにより、&amp;lt;u&amp;gt;Child&amp;lt;/u&amp;gt; は &amp;lt;u&amp;gt;Parent&amp;lt;/u&amp;gt; を継承する。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
子クラスのインスタンスは、親クラスで定義された全てのプロパティとメソッドを利用できる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;extends&amp;lt;/code&amp;gt; を使用した継承の基本例を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 class Animal {&lt;br /&gt;
    constructor(name) {&lt;br /&gt;
       this.name = name;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    speak() {&lt;br /&gt;
       console.log(this.name + &amp;quot; が鳴いた&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // DogはAnimalを継承する&lt;br /&gt;
 class Dog extends Animal {&lt;br /&gt;
    constructor(name, breed) {&lt;br /&gt;
       super(name);        // 親クラスのコンストラクタを呼び出す&lt;br /&gt;
       this.breed = breed; // Dog固有のプロパティを追加する&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // Dog 固有のメソッドを追加する&lt;br /&gt;
    fetch() {&lt;br /&gt;
       console.log(this.name + &amp;quot; がボールを取ってきた&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 const dog = new Dog(&amp;quot;ポチ&amp;quot;, &amp;quot;柴犬&amp;quot;);&lt;br /&gt;
 dog.speak();             // &amp;quot;ポチ が鳴いた&amp;quot; (親クラスのメソッドを使用できる)&lt;br /&gt;
 dog.fetch();             // &amp;quot;ポチ がボールを取ってきた&amp;quot;&lt;br /&gt;
 console.log(dog.name);   // &amp;quot;ポチ&amp;quot;&lt;br /&gt;
 console.log(dog.breed);  // &amp;quot;柴犬&amp;quot;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== superキーワード ====&lt;br /&gt;
&amp;lt;code&amp;gt;super&amp;lt;/code&amp;gt; キーワードには、コンストラクタ内とメソッド内の2つの用途がある。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* コンストラクタ内の &amp;lt;code&amp;gt;super()&amp;lt;/code&amp;gt;&lt;br /&gt;
*: 親クラスのコンストラクタを呼び出す。&lt;br /&gt;
*: &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; にアクセスするより前に呼び出す必要があり、省略すると &amp;lt;u&amp;gt;ReferenceError&amp;lt;/u&amp;gt; が発生する。&lt;br /&gt;
*: &amp;lt;br&amp;gt;&lt;br /&gt;
* メソッド内の &amp;lt;code&amp;gt;super.method()&amp;lt;/code&amp;gt;&lt;br /&gt;
*: 親クラスのメソッドを呼び出す。&lt;br /&gt;
*: 子クラスのメソッド内で親の処理を実行してから拡張する場合に使用する。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;super()&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;super.method()&amp;lt;/code&amp;gt; の両方を示す例を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 class Vehicle {&lt;br /&gt;
    constructor(make, speed) {&lt;br /&gt;
       this.make  = make;&lt;br /&gt;
       this.speed = speed;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    describe() {&lt;br /&gt;
       return this.make + &amp;quot; (最高速度: &amp;quot; + this.speed + &amp;quot; km/h)&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class ElectricCar extends Vehicle {&lt;br /&gt;
    constructor(make, speed, range) {&lt;br /&gt;
       super(make, speed);  // 親コンストラクタを呼び出してから this にアクセスする&lt;br /&gt;
       this.range = range;  // ElectricCar 固有のプロパティ&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    describe() {&lt;br /&gt;
       // super.describe() で親のメソッドを呼び出してから拡張する&lt;br /&gt;
       return super.describe() + &amp;quot; / 航続距離: &amp;quot; + this.range + &amp;quot; km&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 const ev = new ElectricCar(&amp;quot;BEV&amp;quot;, 200, 500);&lt;br /&gt;
 console.log(ev.describe());&lt;br /&gt;
 // &amp;quot;BEV (最高速度: 200 km/h) / 航続距離: 500 km&amp;quot;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== メソッドのオーバーライド ====&lt;br /&gt;
子クラスで親クラスと同名のメソッドを定義すると、親のメソッドがオーバーライド (上書き) される。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;super.method()&amp;lt;/code&amp;gt; を呼び出してから処理を追加することにより、親の実装を再利用しつつ拡張することができる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
オーバーライドの例を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 class Logger {&lt;br /&gt;
    log(message) {&lt;br /&gt;
       console.log(message);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // Loggerを継承してタイムスタンプ付きのログに拡張する&lt;br /&gt;
 class TimestampedLogger extends Logger {&lt;br /&gt;
    log(message) {&lt;br /&gt;
       // 親のlogを呼び出してから拡張する&lt;br /&gt;
       const timestamp = new Date().toISOString();&lt;br /&gt;
       super.log(&amp;quot;[&amp;quot; + timestamp + &amp;quot;] &amp;quot; + message);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 const logger = new TimestampedLogger();&lt;br /&gt;
 logger.log(&amp;quot;アプリケーションが起動しました&amp;quot;);&lt;br /&gt;
 // &amp;quot;[2026-02-19T00:00:00.000Z] アプリケーションが起動しました&amp;quot;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== プロトタイプチェーン ==&lt;br /&gt;
プロトタイプチェーンは、JavaScriptのプロトタイプベースの継承の核心となる仕組みである。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文が導入された後も、継承の内部メカニズムはプロトタイプチェーンによって実現されている。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
この仕組みを理解することで、JavaScriptのオブジェクトモデルをより深く把握できる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== プロトタイプの基本概念 ====&lt;br /&gt;
全てのJavaScriptオブジェクトは、内部プロパティ &amp;lt;code&amp;gt;[[Prototype]]&amp;lt;/code&amp;gt; を持つ。&amp;lt;br&amp;gt;&lt;br /&gt;
この内部プロパティは、&amp;lt;code&amp;gt;Object.getPrototypeOf()&amp;lt;/code&amp;gt; を使用して取得できる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
非推奨の &amp;lt;code&amp;gt;__proto__&amp;lt;/code&amp;gt; プロパティも同様の機能を持つが、コードでは &amp;lt;code&amp;gt;Object.getPrototypeOf()&amp;lt;/code&amp;gt; の使用を推奨する。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
プロトタイプチェーンの終端は &amp;lt;u&amp;gt;null&amp;lt;/u&amp;gt; であり、&amp;lt;code&amp;gt;Object.prototype&amp;lt;/code&amp;gt; のプロトタイプが &amp;lt;u&amp;gt;null&amp;lt;/u&amp;gt; となる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;Object.getPrototypeOf()&amp;lt;/code&amp;gt; でチェーンを辿る例を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 class Animal {&lt;br /&gt;
    speak() {&lt;br /&gt;
       console.log(&amp;quot;鳴く&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Dog extends Animal {}&lt;br /&gt;
 &lt;br /&gt;
 const dog = new Dog();&lt;br /&gt;
 &lt;br /&gt;
 // プロトタイプチェーンを確認する&lt;br /&gt;
 console.log(Object.getPrototypeOf(dog) === Dog.prototype);                  // true&lt;br /&gt;
 console.log(Object.getPrototypeOf(Dog.prototype) === Animal.prototype);     // true&lt;br /&gt;
 console.log(Object.getPrototypeOf(Animal.prototype) === Object.prototype);  // true&lt;br /&gt;
 console.log(Object.getPrototypeOf(Object.prototype));                       // null (チェーンの終端)&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== プロトタイプチェーンの仕組み ====&lt;br /&gt;
オブジェクトのプロパティやメソッドにアクセスすると、JavaScriptエンジンは以下の順序で探索を行う。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
# オブジェクト自身のプロパティを探索する。&lt;br /&gt;
# 見つからない場合、&amp;lt;code&amp;gt;[[Prototype]]&amp;lt;/code&amp;gt; (プロトタイプ) のプロパティを探索する。&lt;br /&gt;
# 見つからない場合、プロトタイプのプロトタイプを探索する。&lt;br /&gt;
# &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; に到達しても見つからない場合、&amp;lt;u&amp;gt;undefined&amp;lt;/u&amp;gt; を返す。&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;子のプロパティが親の同名プロパティを隠す現象をプロパティのシャドウイングと呼ぶ。&amp;lt;/u&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
多段継承でのプロパティ探索の実演を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 class A {&lt;br /&gt;
    hello() { return &amp;quot;Aのhello&amp;quot;; }&lt;br /&gt;
    common() { return &amp;quot;Aのcommon&amp;quot;; }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class B extends A {&lt;br /&gt;
    hello() { return &amp;quot;Bのhello&amp;quot;; }  // Aのhelloをシャドウイングする&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class C extends B {&lt;br /&gt;
    // helloもcommonも定義しない&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 const c = new C();&lt;br /&gt;
 &lt;br /&gt;
 // helloはCにない → Bにある → Bのhelloを使用する&lt;br /&gt;
 console.log(c.hello());   // &amp;quot;Bのhello&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 // commonはCにない → Bにない → Aにある → Aのcommonを使用する&lt;br /&gt;
 console.log(c.common());  // &amp;quot;Aのcommon&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 // unknownは、CにもBにもAにもObject.prototypeにもない&lt;br /&gt;
 console.log(c.unknown);   // undefined&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== classとプロトタイプの関係 ====&lt;br /&gt;
&amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文はシンタックスシュガーであり、内部的にはプロトタイプベースの継承を使用している。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文とプロトタイプベースの等価なコードを以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 // class 構文&lt;br /&gt;
 class Animal {&lt;br /&gt;
    constructor(name) {&lt;br /&gt;
       this.name = name;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    speak() {&lt;br /&gt;
       console.log(this.name + &amp;quot; が鳴く&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class Dog extends Animal {&lt;br /&gt;
    constructor(name, breed) {&lt;br /&gt;
       super(name);&lt;br /&gt;
       this.breed = breed;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // 上記と等価なプロトタイプベースのコード&lt;br /&gt;
 function AnimalFn(name) {&lt;br /&gt;
    this.name = name;&lt;br /&gt;
 }&lt;br /&gt;
 AnimalFn.prototype.speak = function() {&lt;br /&gt;
    console.log(this.name + &amp;quot; が鳴く&amp;quot;);&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 function DogFn(name, breed) {&lt;br /&gt;
    AnimalFn.call(this, name);  // super(name) に相当する&lt;br /&gt;
    this.breed = breed;&lt;br /&gt;
 }&lt;br /&gt;
 // プロトタイプチェーンを設定する (extendsに相当する)&lt;br /&gt;
 Object.setPrototypeOf(DogFn.prototype, AnimalFn.prototype);&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
下表に、&amp;lt;code&amp;gt;class&amp;lt;/code&amp;gt; 構文とプロトタイプベースの対応関係を示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ class構文とプロトタイプの対応表&lt;br /&gt;
! class構文 !! プロトタイプベースの等価コード !! 説明&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;class Animal {}&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;function Animal() {}&amp;lt;/u&amp;gt; || クラス宣言はコンストラクタ関数に対応する&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;constructor(name) { this.name = name; }&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;function Animal(name) { this.name = name; }&amp;lt;/u&amp;gt; || コンストラクタ本体はそのまま関数本体になる&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;speak() { ... }&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;Animal.prototype.speak = function() { ... };&amp;lt;/u&amp;gt; || インスタンスメソッドはprototypeに追加される&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;static create() { ... }&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;Animal.create = function() { ... };&amp;lt;/u&amp;gt; || 静的メソッドはコンストラクタ関数自体のプロパティになる&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;class Dog extends Animal&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;Object.setPrototypeOf(Dog.prototype, Animal.prototype);&amp;lt;/u&amp;gt; || extendsはプロトタイプチェーンを設定する&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;super(name)&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;Animal.call(this, name);&amp;lt;/u&amp;gt; || super()は親コンストラクタをthisに対して呼び出す&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;u&amp;gt;super.speak()&amp;lt;/u&amp;gt; || &amp;lt;u&amp;gt;Animal.prototype.speak.call(this);&amp;lt;/u&amp;gt; || super.method()は親のprototypeのメソッドを呼び出す&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 型チェック ==&lt;br /&gt;
JavaScriptでオブジェクトの型を検査するには、&amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;typeof&amp;lt;/code&amp;gt; の2つの演算子を使い分ける。&amp;lt;br&amp;gt;&lt;br /&gt;
それぞれ用途が異なるため、適切に選択することが重要である。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== instanceof 演算子 ====&lt;br /&gt;
&amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; 演算子は、オブジェクトがあるコンストラクタ (クラス) のインスタンスであるかどうかを、プロトタイプチェーンを辿って検査する。&amp;lt;br&amp;gt;&lt;br /&gt;
子クラスのインスタンスは親クラスの &amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; でも &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; を返すため、継承チェーン全体を検査できる。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; の挙動を示す例を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 class Animal {}&lt;br /&gt;
 class Dog extends Animal {}&lt;br /&gt;
 class Cat extends Animal {}&lt;br /&gt;
 &lt;br /&gt;
 const dog = new Dog();&lt;br /&gt;
 &lt;br /&gt;
 console.log(dog instanceof Dog);     // true  (Dogのインスタンスである)&lt;br /&gt;
 console.log(dog instanceof Animal);  // true  (プロトタイプチェーンを辿ってAnimalも見つかる)&lt;br /&gt;
 console.log(dog instanceof Cat);     // false (Catのインスタンスではない)&lt;br /&gt;
 console.log(dog instanceof Object);  // true  (全てのオブジェクトはObjectのインスタンスである)&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== typeof との違い ====&lt;br /&gt;
&amp;lt;code&amp;gt;typeof&amp;lt;/code&amp;gt; はプリミティブ型の判定に使用し、&amp;lt;code&amp;gt;instanceof&amp;lt;/code&amp;gt; はオブジェクトの型 (コンストラクタ) の判定に使用する。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;typeof null === &amp;quot;object&amp;quot;&amp;lt;/u&amp;gt; となる点は言語仕様上の既知の問題 (バグ) であり、nullチェックには &amp;lt;code&amp;gt;=== null&amp;lt;/code&amp;gt; を使用する必要がある。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
下表に、代表的な値に対する &amp;lt;code&amp;gt;typeof&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;instanceof Object&amp;lt;/code&amp;gt; の結果を示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ typeof vs instanceof 比較表&lt;br /&gt;
! 値 !! typeof の結果 !! instanceof Object&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;object&amp;quot;&amp;lt;/code&amp;gt; (既知の問題) || false&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;undefined&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;undefined&amp;quot;&amp;lt;/code&amp;gt; || false&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;quot;文字列&amp;quot;&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;string&amp;quot;&amp;lt;/code&amp;gt; || false&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;number&amp;quot;&amp;lt;/code&amp;gt; || false&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;boolean&amp;quot;&amp;lt;/code&amp;gt; || false&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;object&amp;quot;&amp;lt;/code&amp;gt; || true&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;[]&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;object&amp;quot;&amp;lt;/code&amp;gt; || true&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;function() {}&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;function&amp;quot;&amp;lt;/code&amp;gt; || true&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;new Date()&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;object&amp;quot;&amp;lt;/code&amp;gt; || true&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;new Dog()&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;&amp;quot;object&amp;quot;&amp;lt;/code&amp;gt; || true&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
型チェックの使い分けの例を以下に示す。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 function processValue(value) {&lt;br /&gt;
    // null チェック: typeof では &amp;quot;object&amp;quot; になるため === null を使用する&lt;br /&gt;
    if (value === null) {&lt;br /&gt;
       console.log(&amp;quot;null です&amp;quot;);&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // プリミティブ型の判定には typeof を使用する&lt;br /&gt;
    if (typeof value === &amp;quot;string&amp;quot;) {&lt;br /&gt;
       console.log(&amp;quot;文字列: &amp;quot; + value.toUpperCase());&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    if (typeof value === &amp;quot;number&amp;quot;) {&lt;br /&gt;
       console.log(&amp;quot;数値: &amp;quot; + value.toFixed(2));&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // オブジェクトの型の判定には instanceof を使用する&lt;br /&gt;
    if (value instanceof Date) {&lt;br /&gt;
       console.log(&amp;quot;日付: &amp;quot; + value.toISOString());&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    if (Array.isArray(value)) {&lt;br /&gt;
       // 配列チェックには Array.isArray() が確実である&lt;br /&gt;
       console.log(&amp;quot;配列 (要素数: &amp;quot; + value.length + &amp;quot;)&amp;quot;);&lt;br /&gt;
       return;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    console.log(&amp;quot;オブジェクト&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 processValue(null);         // &amp;quot;null です&amp;quot;&lt;br /&gt;
 processValue(&amp;quot;hello&amp;quot;);      // &amp;quot;文字列: HELLO&amp;quot;&lt;br /&gt;
 processValue(3.14159);      // &amp;quot;数値: 3.14&amp;quot;&lt;br /&gt;
 processValue(new Date());   // &amp;quot;日付: 2026-02-19T...&amp;quot;&lt;br /&gt;
 processValue([1, 2, 3]);    // &amp;quot;配列 (要素数: 3)&amp;quot;&lt;br /&gt;
 processValue({ x: 1 });     // &amp;quot;オブジェクト&amp;quot;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ReactのErrorBoundaryとクラス継承 ==&lt;br /&gt;
&amp;lt;u&amp;gt;Reactでは関数コンポーネントとHooksが主流となっているが、ErrorBoundaryは現在もクラスコンポーネントで実装しなければならない機能の代表例である。&amp;lt;/u&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
これは、エラーキャッチに必要なライフサイクルメソッドがHooksで代替できないためであり、クラス継承が実際の開発において今なお不可欠であることを示している。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== ErrorBoundaryとは ====&lt;br /&gt;
ErrorBoundaryは、子コンポーネントツリーのレンダリングエラーをキャッチしてアプリケーション全体のクラッシュを防ぎ、フォールバックUIを表示するコンポーネントである。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* キャッチできるエラー&lt;br /&gt;
*: レンダリング中に発生したエラー&lt;br /&gt;
*: ライフサイクルメソッド内で発生したエラー&lt;br /&gt;
*: コンストラクタ内で発生したエラー&lt;br /&gt;
*: &amp;lt;br&amp;gt;&lt;br /&gt;
* キャッチできないエラー&lt;br /&gt;
*: イベントハンドラ内で発生したエラー (try / catchで対処する)&lt;br /&gt;
*: 非同期コード内で発生したエラー (Promiseのrejection等)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== クラス継承が必要な理由 ====&lt;br /&gt;
ErrorBoundaryには以下の2つのライフサイクルメソッドが必要であり、いずれもクラスコンポーネント専用である。&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ 各メソッドの動作&lt;br /&gt;
! メソッド !! 動作&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;static getDerivedStateFromError(error)&amp;lt;/code&amp;gt; || エラー発生時に状態を更新してフォールバックUIをレンダリングするために使用する。&amp;lt;br&amp;gt;静的メソッドであり、&amp;lt;code&amp;gt;static&amp;lt;/code&amp;gt; キーワードを付けて定義する。&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;componentDidCatch(error, errorInfo)&amp;lt;/code&amp;gt; || エラーの詳細情報をログに記録するために使用する。&amp;lt;br&amp;gt;エラーのスタックトレース等の情報 (&amp;lt;code&amp;gt;errorInfo.componentStack&amp;lt;/code&amp;gt;) を参照できる。&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;React Hooksには、&amp;lt;code&amp;gt;getDerivedStateFromError&amp;lt;/code&amp;gt; と &amp;lt;code&amp;gt;componentDidCatch&amp;lt;/code&amp;gt; に相当する機能が存在しない。&amp;lt;/u&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;そのため、ErrorBoundaryは現在もクラスコンポーネントで実装する必要がある。&amp;lt;/u&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== ErrorBoundaryの実装例 ====&lt;br /&gt;
* ErrorBoundaryの実装例&lt;br /&gt;
*: &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 import React from &amp;quot;react&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 class ErrorBoundary extends React.Component {&lt;br /&gt;
    constructor(props) {&lt;br /&gt;
       super(props);&lt;br /&gt;
       this.state = {&lt;br /&gt;
          hasError : false,&lt;br /&gt;
          error    : null,&lt;br /&gt;
       };&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // エラー発生時にstateを更新してフォールバックUIをレンダリングする&lt;br /&gt;
    static getDerivedStateFromError(error) {&lt;br /&gt;
       return {&lt;br /&gt;
          hasError : true,&lt;br /&gt;
          error    : error,&lt;br /&gt;
       };&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // エラーの詳細情報をログに記録する&lt;br /&gt;
    componentDidCatch(error, errorInfo) {&lt;br /&gt;
       console.error(&amp;quot;ErrorBoundary がエラーをキャッチしました:&amp;quot;, error);&lt;br /&gt;
       console.error(&amp;quot;コンポーネントスタック:&amp;quot;, errorInfo.componentStack);&lt;br /&gt;
 &lt;br /&gt;
       // 外部エラートラッキングサービスへの送信例&lt;br /&gt;
       // reportError(error, errorInfo);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // エラー状態をリセットしてコンテンツを再表示する&lt;br /&gt;
    handleReset = () =&amp;gt; {&lt;br /&gt;
       this.setState({ hasError: false, error: null });&lt;br /&gt;
    };&lt;br /&gt;
 &lt;br /&gt;
    render() {&lt;br /&gt;
       if (this.state.hasError) {&lt;br /&gt;
          return (&lt;br /&gt;
             &amp;lt;div&amp;gt;&lt;br /&gt;
                &amp;lt;h2&amp;gt;予期しないエラーが発生しました&amp;lt;/h2&amp;gt;&lt;br /&gt;
                &amp;lt;p&amp;gt;{this.state.error?.message}&amp;lt;/p&amp;gt;&lt;br /&gt;
                &amp;lt;button onClick={this.handleReset}&amp;gt;再試行&amp;lt;/button&amp;gt;&lt;br /&gt;
             &amp;lt;/div&amp;gt;&lt;br /&gt;
          );&lt;br /&gt;
       }&lt;br /&gt;
 &lt;br /&gt;
       // エラーがない場合は子コンポーネントをそのまま表示する&lt;br /&gt;
       return this.props.children;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 export default ErrorBoundary;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
*: &amp;lt;br&amp;gt;&lt;br /&gt;
* ErrorBoundaryの使用例&lt;br /&gt;
*: &amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
 import React from &amp;quot;react&amp;quot;;&lt;br /&gt;
 import ErrorBoundary from &amp;quot;./ErrorBoundary&amp;quot;;&lt;br /&gt;
 import UserProfile from &amp;quot;./UserProfile&amp;quot;;&lt;br /&gt;
 import DataTable from &amp;quot;./DataTable&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 function App() {&lt;br /&gt;
    return (&lt;br /&gt;
       &amp;lt;div&amp;gt;&lt;br /&gt;
          {/* アプリケーション全体をラップする */}&lt;br /&gt;
          &amp;lt;ErrorBoundary&amp;gt;&lt;br /&gt;
             &amp;lt;UserProfile userId={1} /&amp;gt;&lt;br /&gt;
          &amp;lt;/ErrorBoundary&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
          {/* 特定のセクションだけをラップすることもできる */}&lt;br /&gt;
          &amp;lt;ErrorBoundary&amp;gt;&lt;br /&gt;
             &amp;lt;DataTable dataSource=&amp;quot;api/records&amp;quot; /&amp;gt;&lt;br /&gt;
          &amp;lt;/ErrorBoundary&amp;gt;&lt;br /&gt;
       &amp;lt;/div&amp;gt;&lt;br /&gt;
    );&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 export default App;&lt;br /&gt;
 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 関連情報 ==&lt;br /&gt;
* [[JavaScriptの基礎 - クラス]]&lt;br /&gt;
*: クラスの宣言、コンストラクタ、メソッド、フィールド、静的メンバー&lt;br /&gt;
* [[JavaScriptの基礎 - thisキーワード]]&lt;br /&gt;
*: thisの動作、bind / call / apply、クラスにおけるthis&lt;br /&gt;
* [[JavaScriptの基礎 - オブジェクトリテラル]]&lt;br /&gt;
*: オブジェクトの作成と操作、プロパティアクセス、メソッド&lt;br /&gt;
* [[JavaScriptの基礎 - アロー関数]]&lt;br /&gt;
*: アロー関数の構文、レキシカルthis&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{#seo:&lt;br /&gt;
|title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki&lt;br /&gt;
|keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,電気回路,電子回路,基板,プリント基板&lt;br /&gt;
|description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This page is {{PAGENAME}} in our wiki about electronic circuits and SUSE Linux&lt;br /&gt;
|image=/resources/assets/MochiuLogo_Single_Blue.png&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
__FORCETOC__&lt;br /&gt;
[[カテゴリ:Web]]&lt;/div&gt;</summary>
		<author><name>Wiki</name></author>
	</entry>
</feed>