diff options
Diffstat (limited to 'files/ja/web/javascript')
60 files changed, 2 insertions, 4152 deletions
diff --git a/files/ja/web/javascript/getting_started/index.html b/files/ja/web/javascript/getting_started/index.html deleted file mode 100644 index b87febbe05..0000000000 --- a/files/ja/web/javascript/getting_started/index.html +++ /dev/null @@ -1,303 +0,0 @@ ---- -title: Getting Started (Javascript Tutorial) -slug: Web/JavaScript/Getting_Started -translation_of: Learn/Getting_started_with_the_web/JavaScript_basics -translation_of_original: Web/JavaScript/Getting_Started ---- -<h2 id="Why_JavaScript.3F" name="Why_JavaScript.3F">Why JavaScript?</h2> -<p>JavaScript is a powerful, complicated, and often misunderstood computer language. It enables the rapid development of applications in which users can enter data and view results easily.</p> -<p>The primary advantage to JavaScript, which is also known as ECMAScript, centers around the Web browser, thus having the ability to produce the same results on all platforms supported by the browser. The examples on this page, just like Google Maps, run on Linux, Windows, and Mac OS. With the recent growth of numerous JavaScript libraries it is now easier to navigate a document, select DOM elements, create animations, handle events, and develop Ajax applications. Unlike the hype around other technologies pushed by various proprietary interests, JavaScript is really the only cross-platform, client-side programming language that is both free and universally adopted.</p> -<h2 id="What_you_should_already_know" name="What_you_should_already_know">What you should already know</h2> -<p>JavaScript is a very easy language to start programming with. All you need is a text editor and a Web browser to get started.</p> -<p>There are many other technologies that can be integrated into and developed along with JavaScript that are beyond the scope of this document. Don't expect to make a whole application like Google Maps all on your first day!</p> -<h2 id="Getting_Started" name="Getting_Started">Getting started</h2> -<p>Getting started with JavaScript is very easy. You don't have to have complicated development programs installed. You don't have to know how to use a shell, program Make, or use a compiler. JavaScript is interpreted by your Web browser. All you have to do is save your program as a text file and then open it up in your Web browser. That's it!</p> -<p>JavaScript is a great programming language for introductory computer languages. It allows instant feedback to the new student and teaches them about tools they will likely find useful in their real life. This is in stark contrast to C, C++, and Java which are really only useful for dedicated software developers.</p> -<h2 id="Browser_Compatibility_Issues" name="Browser_Compatibility_Issues">Browser compatibility issues</h2> -<p>There are variations between what functionality is available in the different browsers. Mozilla, Microsoft IE, Apple Safari, and Opera fluctuate in behavior. We intend on <a href="/en-US/docs/JavaScript/Compatibility" title="en-US/docs/JavaScript/Compatibility">documenting these variations</a>. You can mitigate these issues by using the various cross-platform JavaScript APIs that are available. These APIs provide common functionality and hide these browser fluctuations from you.</p> -<h2 id="How_to_try_the_Examples" name="How_to_try_the_Examples">How to try the examples</h2> -<p>The examples below have some sample code. There are many ways to try these examples out. If you already have your own website, then you should be able to just save these examples as new Web pages on your website.</p> -<p>If you do not have your own website, you can save these examples as files on your computer and open them up with the Web browser you are using now. JavaScript is a very easy language to use for beginning programmers for this reason. You don't need a compiler or a development environment; you and your browser are all you need to get started!</p> -<h2 id="Example:_Catching_a_mouse_click" name="Example:_Catching_a_mouse_click">Example: Catching a mouse click</h2> -<p>The specifics of event handling (event types, handler registration, propagation, etc.) are too extensive to be fully covered in this simple example. However, this example cannot demonstrate catching a mouse click without delving a little into the JavaScript event system. Just keep in mind that this example will only graze the full details about JavaScript events and that if you wish to go beyond the basic capabilities described here, read more about the JavaScript event system.</p> -<p>'Mouse' events are a subset of the total events issued by a Web browser in response to user actions. The following is a list of the events emitted in response to a user's mouse action:</p> -<ul> - <li>Click - issued when a user clicks the mouse</li> - <li>DblClick - issued when a user double-clicks the mouse</li> - <li>MouseDown - issued when a user depresses a mouse button (the first half of a click)</li> - <li>MouseUp - issued when a user releases a mouse button (the second half of a click)</li> - <li>MouseOut - issued when the mouse pointer leaves the graphical bounds of the object</li> - <li>MouseOver - issued when the mouse pointer enters the graphical bounds of the object</li> - <li>MouseMove - issued when the mouse pointer moves while within the graphical bounds of the object</li> - <li>ContextMenu - issued when the user clicks using the right mouse button</li> -</ul> -<p>Note that in the latest versions of HTML, the inline event handlers, i.e. the ones added as tag attributes, are expected to be all lowercase and that event handlers in script are always all lowercase.</p> -<p>The simplest method for capturing these events, to register event handlers - using HTML - is to specify the individual events as attributes for your element. Example:</p> -<pre class="brush:js"> <span onclick="alert('Hello World!');">Click Here</span></pre> -<p>The JavaScript code you wish to execute can be inlined as the attribute value or you can call a function which has been defined in a <script> block within the HTML page:</p> -<pre class="brush:js"><script type="text/javascript"> - function clickHandler () { - alert ("Hello, World!"); - } -</script> -<span onclick="clickHandler();">Click Here</span></pre> -<p>Additionally, the event object which is issued can be captured and referenced, providing the developer with access to specifics about the event such as which object received the event, the event's type, and which mouse button was clicked. Using the inline example again:</p> -<pre class="brush:js"><script type="text/javascript"> - function clickHandler(event) { - var eType = event.type; - /* the following is for compatibility */ - /* Moz populates the target property of the event object */ - /* IE populates the srcElement property */ - var eTarget = event.target || event.srcElement; - - alert( "Captured Event (type=" + eType + ", target=" + eTarget ); - } -</script> -<span onclick="clickHandler(event);">Click Here</span></pre> -<p>In addition to registering to receive events in your HTML, you can likewise set the same attributes of any HTMLElement objects generated by your JavaScript. The example below instantiates a span object, appends it to the page body, and registers the span object to receive mouse-over, mouse-out, mouse-down, and mouse-up events.</p> -<pre class="brush:js"><body></body> -<script type="text/javascript"> - function mouseeventHandler(event) { - /* The following is for compatibility */ - /* IE does NOT by default pass the event object */ - /* obtain a ref to the event if one was not given */ - if (!event) event = window.event; - - /* obtain event type and target as earlier */ - var eType = event.type; - var eTarget = event.target || event.srcElement; - alert(eType +' event on element with id: '+ eTarget.id); - } - - function onloadHandler () { - /* obtain a ref to the 'body' element of the page */ - var body = document.body; - /* create a span element to be clicked */ - var span = document.createElement('span'); - span.id = 'ExampleSpan'; - span.appendChild(document.createTextNode ('Click Here!')); - - /* register the span object to receive specific mouse events - - notice the lowercase of the events but the free choice in the names of the handlers you replace them with. - */ - span.onmousedown = mouseeventHandler; - span.onmouseup = mouseeventHandler; - span.onmouseover = mouseeventHandler; - span.onmouseout = mouseeventHandler; - - /* display the span on the page */ - body.appendChild(span); -} - -window.onload = onloadHandler; // since we replace the handler, we do NOT have () after the function name -</script></pre> -<h2 id="Example:_Catching_a_keyboard_event" name="Example:_Catching_a_keyboard_event">Example: Catching a keyboard event</h2> -<p>Similar to the "Catching a mouse event" example above, catching a keyboard event relies on exploring the JavaScript event system. Keyboard events are fired whenever any key is used on the keyboard.</p> -<p>The list of available keyboard events emitted in response to a keyboard action is considerably smaller than those available for mouse:</p> -<ul> - <li>KeyPress - issued when a key is depressed and released</li> - <li>KeyDown - issued when a key is depressed but hasn't yet been released</li> - <li>KeyUp - issued when a key is released</li> - <li>TextInput (available in Webkit browsers only at time of writing) - issued when text is input either by pasting, speaking, or keyboard. This event will not be covered in this article.</li> -</ul> -<p>In a <a class="new " href="/en-US/docs/DOM/event/keypress" rel="internal">keypress</a> event, the Unicode value of the key pressed is stored in either the <code>keyCode</code> or <code><a href="/en-US/docs/DOM/event.charCode" rel="internal">charCode</a></code> property, never both. If the key pressed generates a character (e.g., 'a'), <code>charCode</code> is set to the code of that character, respecting the letter case (i.e., <code>charCode</code> takes into account whether the shift key is held down). Otherwise, the code of the pressed key is stored in <code>keyCode</code>.</p> -<p>The simplest method for capturing keyboard events is again to register event handlers within the HTML, specifying the individual events as attributes for your element. Example:</p> -<pre class="brush:js"> <input type="text" onkeypress="alert ('Hello World!');" /> -</pre> -<p>As with mouse events, the JavaScript code you wish to execute can be inlined as the attribute value or you can call a function which has been defined in a <script> block within the HTML page:</p> -<pre class="brush:js"><script type="text/javascript"> - function keypressHandler() { - alert ("Hello, World!"); - } -</script> - -<input onkeypress="keypressHandler();" /> -</pre> -<p>Capturing the event and referencing the target (i.e., the actual key that was pressed) is achieved in a similar way to mouse events:</p> -<pre class="brush:js"><script type="text/javascript"> - function keypressHandler(evt) { - var eType = evt.type; // Will return "keypress" as the event type - /* here we again need to use a cross browser method - mozilla based browsers return which and others keyCode. - The <a href="/en-US/docs/JavaScript/Reference/Operators/Conditional_Operator" title="/en-US/docs/JavaScript/Reference/Operators/Conditional_Operator">Conditional operator</a> or ternary is a good choice */ - var keyCode = evt.which?evt.which:evt.keyCode; - var eCode = 'keyCode is ' + keyCode; - var eChar = 'charCode is ' + <span class="typ" style="background-color: transparent; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(43, 145, 175);">String</span><span class="pun" style="background-color: transparent; color: rgb(0, 0, 0); margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;">.</span><span class="pln" style="background-color: transparent; color: rgb(0, 0, 0); margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;">fromCharCode(</span>keyCode); // or evt.charCode - alert ("Captured Event (type=" + eType + ", key Unicode value=" + eCode + ", ASCII value=" + eChar + ")"); - } -</script> -<input onkeypress="keypressHandler(event);" /></pre> -<p>Capturing any key event from the page can be done by registering the event at the document level and handling it in a function:</p> -<pre class="brush:js"><script type="text/javascript"> - document.onkeypress = keypressHandler(event); - document.onkeydown = keypressHandle(event); - document.onkeyup =keypressHandle(event) - -</script></pre> -<p>Here is a complete example that shows key event handling:</p> -<pre class="brush:js"><!DOCTYPE html> -<html> -<head> - <script> - var metaChar = false; - var exampleKey = 16; - function keyEvent(event) { - var key = event.keyCode || event.which; // alternative to ternary - if there is no keyCode, use which - var keychar = String.fromCharCode(key); - if (key==exampleKey) { metaChar = true; } - if (key!=exampleKey) { - if (metaChar) { - alert("Combination of metaKey + " + keychar) - metaChar = false; - } else { alert("Key pressed " + key); } - } - } - function metaKeyUp (event) { - var key = event.keyCode || event.which; - if (key==exampleKey) { metaChar = false; } - } - </script> -</head> -<body onkeydown="keyEvent(event)" onkeyup="metaKeyUp(event)"> - Try pressing any key! -</body> -</html></pre> -<h3 id="Browser_bugs_and_quirks">Browser bugs and quirks</h3> -<p>The two properties made available through the key events are <code>keyCode</code> and <code>charCode</code>. In simple terms, <code>keyCode</code> refers to the actual keyboard key that was pressed by the user, while <code>charCode</code> is intended to return that key's ASCII value. These two values may not necessarily be the same; for instance, a lower case 'a' and an upper case 'A' have the same <code>keyCode</code>, because the user presses the same key, but a different <code>charCode</code> because the resulting character is different.</p> -<p>The way in which browsers interpret the charCode is not a consistently-applied process. For example, Internet Explorer and Opera do not support <code>charCode</code>. However, they give the character information in <code>keyCode</code>, but only onkeypress. Onkeydown and onkeyup <code>keyCode</code> contain key information. Firefox uses a different word, "which", to distinguish the character.</p> -<p>Refer to the Mozilla Documentation on <a href="/en-US/docs/DOM/Event/UIEvent/KeyboardEvent" title="https://developer.mozilla.org/en-US/docs/DOM/Event/UIEvent/KeyEvent">Keyboard Events</a> for a further treatment of keyboard events.</p> -<p>{{ draft() }}</p> -<h2 id="Example:_Dragging_images_around" name="Example:_Dragging_images_around">Example: Dragging images around</h2> -<p>The following example allows moving the image of Firefox around the page:</p> -<pre class="brush:js"><!DOCTYPE html> -<html> -<head> -<style type='text/css'> -img { position: absolute; } -</style> - -<script type='text/javascript'> -window.onload = function() { - - movMeId = document.getElementById("ImgMov"); - movMeId.style.top = "80px"; - movMeId.style.left = "80px"; - - document.onmousedown = coordinates; - document.onmouseup = mouseup; - - function coordinates(e) { - if (e == null) { e = window.event;} - - // e.srcElement holds the target element in IE, whereas e.target holds the target element in Firefox - // Both properties return the HTML element the event took place on. - - var sender = (typeof( window.event ) != "undefined" ) ? e.srcElement : e.target; - - if (sender.id=="ImgMov") { - mouseover = true; - pleft = parseInt(movMeId.style.left); - ptop = parseInt(movMeId.style.top); - xcoor = e.clientX; - ycoor = e.clientY; - document.onmousemove = moveImage; - return false; - } else { - return false; - } - } - - function moveImage(e) { - if (e == null) { e = window.event; } - movMeId.style.left = pleft+e.clientX-xcoor+"px"; - movMeId.style.top = ptop+e.clientY-ycoor+"px"; - return false; - } - - function mouseup(e) { - document.onmousemove = null; - } -} -</script> -</head> - -<body> - <img id="ImgMov" src="http://placehold.it/100x100&text=JS" width="64" height="64" /> - <p>Drag and drop around the image in this page.</p> -</body> - -</html></pre> -<h2 id="Example:_Resizing_things" name="Example:_Resizing_things">Example: Resizing things</h2> -<div> - Example of resizing an image (the actual image is not resized, only the image's rendering.) - <pre class="brush:js"> <!DOCTYPE html> - <html> - <head> - <style> - #resizeImage { - margin-left: 100px; - } - </style> - <script> - window.onload = function() { - - var resizeId = document.getElementById("resizeImage"); - var resizeStartCoordsX, - resizeStartCoordsY, - resizeEndCoordsX, - resizeEndCoordsY; - - var resizeEndCoords; - var resizing = false; - - document.onmousedown = coordinatesMousedown; - document.onmouseup = coordinatesMouseup; - - function coordinatesMousedown(e) { - if (e == null) { - e = window.event; - } - - var element = (typeof( window.event ) != 'undefined' ) ? e.srcElement : e.target; - - if (element.id == "resizeImage") { - resizing = true; - resizeStartCoordsX = e.clientX; - resizeStartCoordsY = e.clientY; - } - return false; - } - - function coordinatesMouseup(e) { - if (e == null) { - e = window.event; - } - - if (resizing === true) { - var currentImageWidth = parseInt(resizeId.width); - var currentImageHeight = parseInt(resizeId.height); - - resizeEndCoordsX = e.clientX; - resizeEndCoordsY = e.clientY; - - resizeId.style.height = currentImageHeight - (resizeStartCoordsY - resizeEndCoordsY) + 'px'; - resizeId.style.width = currentImageWidth - (resizeStartCoordsX - resizeEndCoordsX) + 'px'; - - resizing = false; - } - return false; - } - } - </script> - </head> - - <body> - <img id="resizeImage" src="http://upload.wikimedia.org/wikipedia/commons/e/e7/Mozilla_Firefox_3.5_logo_256.png" -width="64" height="64" /> - <p>Click on the image and drag for resizing.</p> - </body> - - </html></pre> -</div> -<h2 id="Example:_Drawing_Lines" name="Example:_Drawing_Lines">Example: Drawing Lines</h2> -<p><span class="diff_add">{{todo("Need Content. Or, remove headline")}}</span></p> diff --git a/files/ja/web/javascript/guide/class-based_vs._prototype-based_languages/index.html b/files/ja/web/javascript/guide/class-based_vs._prototype-based_languages/index.html deleted file mode 100644 index 800f222ea4..0000000000 --- a/files/ja/web/javascript/guide/class-based_vs._prototype-based_languages/index.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Class-Based vs. Prototype-Based Languages -slug: Web/JavaScript/Guide/Class-Based_vs._Prototype-Based_Languages ---- -<h3 id=".E3.82.AF.E3.83.A9.E3.82.B9.E3.83.99.E3.83.BC.E3.82.B9.E8.A8.80.E8.AA.9E.E3.81.A8.E3.83.97.E3.83.AD.E3.83.88.E3.82.BF.E3.82.A4.E3.83.97.E3.83.99.E3.83.BC.E3.82.B9.E8.A8.80.E8.AA.9E" name=".E3.82.AF.E3.83.A9.E3.82.B9.E3.83.99.E3.83.BC.E3.82.B9.E8.A8.80.E8.AA.9E.E3.81.A8.E3.83.97.E3.83.AD.E3.83.88.E3.82.BF.E3.82.A4.E3.83.97.E3.83.99.E3.83.BC.E3.82.B9.E8.A8.80.E8.AA.9E">クラスベース言語とプロトタイプベース言語</h3> -<p>Java や C++ といったクラスベースのオブジェクト指向言語はクラスとインスタンスという 2 つの異なる実体があるという概念に基づいています。</p> -<ul> <li>クラスはあるオブジェクトの集合を特徴付けるすべてのプロパティ(Java ではメソッドとフィールドを、C++ ではメンバをプロパティと見なす)を定義する。クラスとはそれが表すオブジェクトの集合の特定のメンバではなく、抽象的なものである。例えば、Employee クラスで従業員すべてを含む集合を表す。</li> <li>一方、インスタンスはクラスを実例にしたものである。つまり、そのメンバの 1 つということである。例えば、Victoria は Employee クラスのインスタンスとなることができる。このクラスは特定の個人を従業者として表すものである。インスタンスはその親クラスのプロパティを正確に保持する(それに他ならない)。</li> -</ul> -<p>JavaScript のようなプロトタイプベース言語はこの区別がありません。単にオブジェクトがあるだけです。プロトタイプベース言語には原型的なオブジェクトという概念があります。このオブジェクトは新しいオブジェクトの初期プロパティを取得する元になるテンプレートとして使用されます。どのオブジェクトもそれ独自のプロパティを指定できます。オブジェクト作成時にも実行時にも可能です。さらに、どのオブジェクトも別のオブジェクトに対するプロトタイプとして関連付けることができます。2 つ目のオブジェクトが 1 つ目のオブジェクトのプロトタイプを共有するということもできます。</p> -<h4 id=".E3.82.AF.E3.83.A9.E3.82.B9.E3.81.AE.E5.AE.9A.E7.BE.A9" name=".E3.82.AF.E3.83.A9.E3.82.B9.E3.81.AE.E5.AE.9A.E7.BE.A9">クラスの定義</h4> -<p>クラスベース言語ではクラス定義ごとにクラスを定義します。定義では特殊なメソッドを指定してそのクラスのインスタンスを作成することができます。そのようなメソッドはコンストラクタと呼びます。コンストラクタメソッドはインスタンスのプロパティに対する初期値を指定することができます。また、作成時に他の適当な処理を実行することもできます。new 演算子をコンストラクタメソッドと一緒に用いることでクラスのインスタンスを作成できます。</p> -<p>JavaScript は同様のモデルに従っていますが、コンストラクタと別になっているクラス定義がありません。その代わりに、プロパティと値からなる特定の初期的なセットを持つオブジェクトを作成するコンストラクタ関数を定義します。どの JavaScript 関数もコンストラクタとして使用できます。new 演算子をコンストラクタ関数とともに使用することで新しいオブジェクトを作成します。</p> -<h4 id=".E3.82.B5.E3.83.96.E3.82.AF.E3.83.A9.E3.82.B9.E3.81.A8.E7.B6.99.E6.89.BF" name=".E3.82.B5.E3.83.96.E3.82.AF.E3.83.A9.E3.82.B9.E3.81.A8.E7.B6.99.E6.89.BF">サブクラスと継承</h4> -<p>クラスベース言語ではクラス定義を通じてクラスの階層を作ります。クラス定義では新しいクラスがある既存のクラスのサブクラスになるように指定することができます。サブクラスはスーパークラスの全プロパティを継承します。さらに新しくプロパティを追加したり継承したものを変更することもできます。例えば、Employee クラスが name および dept プロパティのみを含んでおり、Manager は reports プロパティを追加する Employee のサブクラスであるとします。この場合、Manager クラスのインスタンスは name、dept、reports という 3 つのプロパティをすべて持つことになります。</p> -<p>JavaScript では、原型的なオブジェクトをどのコンストラクタ関数にも結びつけることができるようにして継承を実装しています。そのため、全く同じような Employee と Manager の例を作成することができますが、使用する用語が若干異なります。まず、Employee コンストラクタ関数を定義します。これは name および dept プロパティを指定します。次に Manager コンストラクタ関数を定義します。これは reports プロパティを指定します。最後に新しい Employee オブジェクトを Manager コンストラクタ関数に対するプロトタイプとして代入します。そして新しい Manager を作成すると、このオブジェクトは Employee オブジェクトから name および dept プロパティを継承します。</p> -<h4 id=".E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E8.BF.BD.E5.8A.A0.E3.81.A8.E5.89.8A.E9.99.A4" name=".E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E8.BF.BD.E5.8A.A0.E3.81.A8.E5.89.8A.E9.99.A4">プロパティの追加と削除</h4> -<p>クラスベース言語では一般的にクラスをコンパイル時に生成し、コンパイル時または実行時にクラスのインスタンスを作成します。クラス定義後にそのクラスのプロパティの数や型を変更することはできません。しかし、JavaScript ではどんなオブジェクトでも実行時にプロパティを追加したり削除したりすることができます。あるオブジェクトのセットでプロトタイプとして使用されているオブジェクトにプロパティを追加すると、そのプロトタイプの使用元であるオブジェクトにも新しいプロパティが追加されます。</p> -<h4 id=".E9.81.95.E3.81.84.E3.81.AE.E6.A6.82.E8.A6.81" name=".E9.81.95.E3.81.84.E3.81.AE.E6.A6.82.E8.A6.81">違いの概要</h4> -<p>次の表でこれらの違いをいくつか短くまとめてみます。この章の残りで、JavaScript のコンストラクタとプロトタイプを用いてオブジェクト階層を作成することについての詳細を説明していきます。また、この方法が Java ではどう変わるかという比較もします。</p> -<table class="fullwidth-table"> <tbody> <tr> <th>クラスベース (Java)</th> <th>プロトタイプベース (JavaScript)</th> </tr> <tr> <td>クラスとインスタンスは異なる実体である。</td> <td>すべてのオブジェクトはインスタンスである。</td> </tr> <tr> <td>クラス定義を用いてクラスを定義する。また、コンストラクタメソッドを用いてクラスをインスタンス化する。</td> <td>コンストラクタ関数を用いてオブジェクトのセットを定義し、作成する。</td> </tr> <tr> <td><code>new</code> 演算子を用いて単一のオブジェクトを作成する。</td> <td>同じ。</td> </tr> <tr> <td>既存のクラスのサブクラスを定義するクラス定義を用いてオブジェクト階層を構築する。</td> <td>コンストラクタ関数に結びつけられたプロトタイプとしてオブジェクトを代入することでオブジェクト階層を構築する。</td> </tr> <tr> <td>クラスチェーンに従ってプロパティを継承する。</td> <td>プロトタイプチェーンに従ってプロパティを継承する。</td> </tr> <tr> <td>クラス定義がクラスの全インスタンスの全プロパティを指定する。実行時に動的にプロパティを追加することはできない。</td> <td>コンストラクタ関数またはプロトタイプがプロパティの初期セットを指定する。個々のオブジェクトやオブジェクトの全体のセットに動的にプロパティを追加したり、それらからプロパティを除去したりできる。</td> </tr> </tbody> -</table> -<div class="noinclude"> -<p>{{ PreviousNext("Core_JavaScript_1.5_Guide:Predefined_Core_Objects:String_Object", "Core_JavaScript_1.5_Guide:The_Employee_Example") }}</p> -</div> -<p>{{ languages( { "zh-tw": "zh_tw/Core_JavaScript_1.5_教學/以類別為基礎的語言_vs._以原型為基礎的語言", "en": "en/Core_JavaScript_1.5_Guide/Class-Based_vs._Prototype-Based_Languages", "es": "es/Gu\u00eda_JavaScript_1.5/Lenguajes_basados_en_clases_frente_a_basados_en_prototipos", "fr": "fr/Guide_JavaScript_1.5/Langages_bas\u00e9s_sur_les_classes_et_langages_bas\u00e9s_sur_les_prototypes", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/J\u0119zyki_oparte_na_klasach_vs._oparte_na_prototypach", "zh-cn": "cn/Core_JavaScript_1.5_Guide/Class-Based_vs._Prototype-Based_Languages" } ) }}</p> diff --git a/files/ja/web/javascript/guide/core_language_features/index.html b/files/ja/web/javascript/guide/core_language_features/index.html deleted file mode 100644 index 2161ec589e..0000000000 --- a/files/ja/web/javascript/guide/core_language_features/index.html +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Core Language Features -slug: Web/JavaScript/Guide/Core_Language_Features ---- -<div> -{{page("/ja/docs/Core_JavaScript_1.5_Guide/Values()")}} -{{page("/ja/docs/Core_JavaScript_1.5_Guide/Variables()")}} -{{page("/ja/docs/Core_JavaScript_1.5_Guide/Constants()")}} -{{page("/ja/docs/Core_JavaScript_1.5_Guide/Literals()")}} -{{page("/ja/docs/Core_JavaScript_1.5_Guide/Unicode()")}}</div> diff --git a/files/ja/web/javascript/guide/creating_a_regular_expression/index.html b/files/ja/web/javascript/guide/creating_a_regular_expression/index.html deleted file mode 100644 index 19935b8b55..0000000000 --- a/files/ja/web/javascript/guide/creating_a_regular_expression/index.html +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: 正規表現の作成 -slug: Web/JavaScript/Guide/Creating_a_Regular_Expression ---- -<h2 id="正規表現の作成">正規表現の作成</h2> -<p>正規表現は 2 つの方法で作ることができます。</p> -<ul> - <li>次のように、正規表現リテラルを使用する。</li> -</ul> -<pre>var re = /ab+c/; </pre> -<dl> - <dd> - <dl> - <dd> - 正規表現リテラルでは、スクリプトが評価されるときにその正規表現をコンパイルします。正規表現を定数として残しておくときは、この方法を使用するとよりよいパフォーマンスが得られます。</dd> - </dl> - </dd> -</dl> -<ul> - <li>次のように、<a href="/ja/JavaScript/Reference/Global_Objects/RegExp" title="ja/JavaScript/Reference/Global_Objects/RegExp">RegExp</a> オブジェクトのコンストラクタ関数を呼び出す。</li> -</ul> -<pre>var re = new RegExp("ab+c"); </pre> -<dl> - <dd> - <dl> - <dd> - コンストラクタ関数を使用すると、実行時にその正規表現をコンパイルします。正規表現パターンが変わることがわかっている場合や、パターンがわからない場合、ユーザが入力するなど、別のソースからパターンを取得する場合はコンストラクタ関数を使用してください。</dd> - </dl> - </dd> -</dl> -<p>{{ PreviousNext("JavaScript/Guide/Operators/Special_Operators", "JavaScript/Guide/Writing_a_Regular_Expression_Pattern") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/defining_getters_and_setters/index.html b/files/ja/web/javascript/guide/creating_new_objects/defining_getters_and_setters/index.html deleted file mode 100644 index 8ee9381575..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/defining_getters_and_setters/index.html +++ /dev/null @@ -1,89 +0,0 @@ ---- -title: ゲッターとセッターの定義 -slug: Web/JavaScript/Guide/Creating_New_Objects/Defining_Getters_and_Setters ---- -<h3 id=".E3.82.B2.E3.83.83.E3.82.BF.E3.81.A8.E3.82.BB.E3.83.83.E3.82.BF.E3.81.AE.E5.AE.9A.E7.BE.A9" name=".E3.82.B2.E3.83.83.E3.82.BF.E3.81.A8.E3.82.BB.E3.83.83.E3.82.BF.E3.81.AE.E5.AE.9A.E7.BE.A9">ゲッターとセッターの定義</h3> - -<p>ゲッターはある属性の値を取得するメソッドです。セッターは属性に値を設定するメソッドです。全ての定義済みコアオブジェクトと、新しいプロパティの追加をサポートしているユーザ定義オブジェクトに対してゲッターとセッターを定義できます。ゲッターとセッターの定義にはオブジェクトリテラル構文を使用します。</p> - -<p>以下の例では、ユーザ定義オブジェクト o についてゲッターとセッターがどのように機能するかを説明します。<a href="/ja/docs/SpiderMonkey/Introduction_to_the_JavaScript_shell">JavaScript シェル</a> とは JavaScript コードをバッチモードで、またはインタラクティブにテストすることができる、開発者向けのアプリケーションのことです。</p> - -<p><code>o</code> オブジェクトのプロパティは以下のとおりです。</p> - -<ul> - <li>o.a - 数値</li> - <li>o.b - o.a に 1 を加えて返すゲッター</li> - <li>o.c - o.a の値にその値の 1/2 の値をセットするセッター</li> -</ul> - -<pre>js> o = new Object; -[object Object] -js> o = {a:7, get b() {return this.a+1; }, set c(x) {this.a = x/2}}; -[object Object] -js> o.a -7 -js> o.b -8 -js> o.c = 50 -js> o.a -25 -js> -</pre> - -<p>次の例では、 Date プロトタイプを拡張して定義済み <code>Date</code> クラスの全インスタンスに year プロパティを追加する様子を表しています。<code>Date</code> クラスの既存の <code>getFullYear</code> および <code>setFullYear</code> メソッドを使用して year プロパティのゲッターとセッターを実装します。</p> - -<p>これらの文は year プロパティに対するゲッターとセッターを定義しています。</p> - -<pre>js> var d = Date.prototype; -js> d.__defineGetter__("year", function() { return this.getFullYear(); }); -js> d.__defineSetter__("year", function(y) { this.setFullYear(y); }); -</pre> - -<p>これらの文は <code>Date</code> オブジェクトで定義したゲッターとセッターを使用しています。</p> - -<pre>js> var now = new Date; -js> print(now.year); -2000 -js> now.year=2001; -987617605170 -js> print(now); -Wed Apr 18 11:13:25 GMT-0700 (Pacific Daylight Time) 2001 -</pre> - -<div class="note">JavaScript 1.5 の開発期間中に <code>getter =</code> や <code>setter =</code> といった式を使用して新しいゲッターやセッターを既存のオブジェクトで定義するようになっていた時期がありました。この構文は現在は廃止予定であり、現行の JS 1.5 エンジンでは警告を発します。また、将来的には構文エラーになります。使用を避けるようにしてください</div> - -<p> </p> - -<h3 id=".E6.A6.82.E8.A6.81" name=".E6.A6.82.E8.A6.81">概要</h3> - -<p>原則的にゲッターとセッターは次のどちらかに属します。</p> - -<ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers">オブジェクト初期化子</a> を用いて定義されたもの</li> - <li>ゲッターやセッターを追加するメソッドを用いてオブジェクトに後から追加されたもの</li> -</ul> - -<p><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers">オブジェクト初期化子</a> を用いてゲッターやセッターを定義する際には、ゲッターメソッドの先頭に <code>get</code> を、セッターメソッドの先頭に <code>set</code> をそれぞれ付けなくてはなりません。セッターメソッドはセットする新しい値を受けわたすための引数を 1 つだけ持ちます。ゲッターメソッドはパラメータを受け取るようにしてはいけません。</p> - -<pre class="eval">o = { - a:7, - <strong>get</strong> b() { return this.a+1; }, - <strong>set</strong> c(x) { this.a = x/2; } -}; -</pre> - -<p>ゲッターもセッターも、<code>__defineGetter__</code> および <code>__defineSetter__</code> という 2 つの特別なメソッドを用いて、オブジェクト作成後でも、そのオブジェクトに追加することができます。両メソッドの第 1 引数にはそのゲッターやセッターの名前を文字列で指定します。第 2 引数にはゲッターやセッターとして呼び出す関数を指定します。前の例を別の方法で実装したものを以下に示します。</p> - -<pre class="eval">o.__defineGetter__("b", function() { return this.a+1; }); -o.__defineSetter__("c", function(x) { this.a = x/2; }); -</pre> - -<p>2 つの形式のうちどちらを選択するかはあなたのプログラミングスタイルや、目の前の課題次第によります。プロトタイプの定義時にオブジェクト初期化子を使用しているのであれば、最初の形式を選択するのがよいでしょう。この形式はよりコンパクトかつ自然です。ゲッターやセッターを後から追加する必要がある場合は、プロトタイプや特定のオブジェクトを書いていないため、第 2 の形式しか使用できません。第 2 の形式は JavaScript の動的性質をおそらく最もよく表していますが、コードが可読性が下がったり、理解しづらいものとなることがあります。</p> - -<div class="note"> -<p>Firefox 3.0 より前のバージョンではゲッターとセッターが DOM 要素に対してサポートされていません。古いバージョンの Firefox では例外を投げることなく失敗します。そのときに例外が必要であれば、HTMLElement のプロトタイプを変更し <code>(HTMLElement.prototype.__define{{ mediawiki.external('SG') }}etter__)</code>、例外を投げるようにして回避してください。</p> - -<p>Firefox 3.0 では、定義済みのプロパティでゲッターとセッターを定義すると例外が投げられます。そのプロパティは事前に削除しておく必要があります。これは古いバージョンの Firefox には当てはまりません。</p> -</div> - -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects/Using_this_for_Object_References", "JavaScript/Guide/Creating_New_Objects/Deleting_Properties") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/defining_methods/index.html b/files/ja/web/javascript/guide/creating_new_objects/defining_methods/index.html deleted file mode 100644 index 74731a99d1..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/defining_methods/index.html +++ /dev/null @@ -1,39 +0,0 @@ ---- -title: メソッドの定義 -slug: Web/JavaScript/Guide/Creating_New_Objects/Defining_Methods ---- -<h3 id=".E3.83.A1.E3.82.BD.E3.83.83.E3.83.89.E3.81.AE.E5.AE.9A.E7.BE.A9" name=".E3.83.A1.E3.82.BD.E3.83.83.E3.83.89.E3.81.AE.E5.AE.9A.E7.BE.A9">メソッドの定義</h3> -<p><em>メソッド</em>とはあるオブジェクトに結びつけられた関数のことです。メソッドは、通常の関数の定義と同じ方法で定義します。既存のオブジェクトに関数を結びつけるには次の構文を使用します。</p> -<pre>object.methodname = function_name -</pre> -<p>ここで、<code>object</code> は既存のオブジェクトを、<code>methodname</code> はメソッドに割り当てる名前を、<code>function_name</code> は関数の名前をそれぞれ表しています。</p> -<p>すると、次のようにしてオブジェクトのコンテキストでそのメソッドを呼び出すことができます。</p> -<pre>object.methodname(params); -</pre> -<p>オブジェクトのコンストラクタ関数にメソッドの定義を含めることで、あるオブジェクトの種類についてのメソッドを定義することができます。例えば、以前に定義した car オブジェクトのプロパティを整形して表示する関数を定義します。</p> -<pre>function displayCar() { - var result = "A Beautiful " + this.year + " " + this.make - + " " + this.model; - pretty_print(result); -} -</pre> -<p><code>pretty_print</code> は水平方向の罫線と文字列を表示する関数です。<code>this</code> を使用してそのメソッドを抱えているオブジェクトを参照しています。</p> -<p>次の文</p> -<pre>this.displayCar = displayCar; -</pre> -<p>をオブジェクトの定義に加えることで、この関数を car のメソッドにすることができます。そうすると、<code>car</code> の完全な定義は次のようになります。</p> -<pre>function car(make, model, year, owner) { - this.make = make; - this.model = model; - this.year = year; - this.owner = owner; - this.displayCar = displayCar; -} -</pre> -<p>すると、次のようにして各オブジェクトについて <code>displayCar</code> メソッドを呼び出すことができます。</p> -<pre>car1.displayCar() -car2.displayCar() -</pre> -<p>こうすると次の図のような出力が得られます。</p> -<p><img alt="Image:obja.gif" class="internal" src="/@api/deki/files/1941/=Obja.gif"> <small><strong>図 7.1:メソッドの出力の表示</strong></small></p> -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects/Defining_Properties_for_an_Object_Type", "JavaScript/Guide/Creating_New_Objects/Using_this_for_Object_References") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/defining_properties_for_an_object_type/index.html b/files/ja/web/javascript/guide/creating_new_objects/defining_properties_for_an_object_type/index.html deleted file mode 100644 index b5136b203e..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/defining_properties_for_an_object_type/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: Defining Properties for an Object Type -slug: >- - Web/JavaScript/Guide/Creating_New_Objects/Defining_Properties_for_an_Object_Type ---- -<h3 id=".E3.81.82.E3.82.8B.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E7.A8.AE.E9.A1.9E.E3.81.AB.E5.AF.BE.E3.81.99.E3.82.8B.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E5.AE.9A.E7.BE.A9" name=".E3.81.82.E3.82.8B.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E7.A8.AE.E9.A1.9E.E3.81.AB.E5.AF.BE.E3.81.99.E3.82.8B.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E5.AE.9A.E7.BE.A9">あるオブジェクトの種類に対するプロパティの定義</h3> -<p><code>prototype</code> プロパティを用いて、定義済みのオブジェクトの種類にプロパティを追加することができます。この方法では、指定した種類のすべてのオブジェクトで共有されるプロパティを定義することになります。そのオブジェクトのあるインスタンス 1 つだけということではありません。次のコードは <code>color</code> プロパティを <code>car</code> という種類の全オブジェクトに追加し、値をオブジェクト <code>car1</code> の <code>color</code> プロパティに代入します。</p> -<pre>car.prototype.color=null; -car1.color="black"; -</pre> -<p>詳しくは <a href="/ja/Core_JavaScript_1.5_Reference" title="ja/Core_JavaScript_1.5_Reference">コア JavaScript リファレンス</a> 内の Function オブジェクトの <a href="/ja/Core_JavaScript_1.5_Reference/Objects/Function#.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3" title="ja/Core_JavaScript_1.5_Reference/Objects/Function#.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3"><code>prototype</code> プロパティ</a> を参照してください。</p> - -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects/Indexing_Object_Properties", "JavaScript/Guide/Creating_New_Objects/Defining_Methods") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/deleting_properties/index.html b/files/ja/web/javascript/guide/creating_new_objects/deleting_properties/index.html deleted file mode 100644 index 749ee722f5..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/deleting_properties/index.html +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: プロパティの削除 -slug: Web/JavaScript/Guide/Creating_New_Objects/Deleting_Properties ---- -<h2 id="プロパティの削除">プロパティの削除</h2> -<p><code>delete</code> 演算子を用いることでプロパティを除去することができます。次のコードでプロパティの除去方法を示します。</p> -<pre>// 新しいオブジェクト myobj を作成。2 つのプロパティ、a および b を持つ。 -myobj = new Object; -myobj.a = 5; -myobj.b = 12; - -// a プロパティを除去。myobj には b プロパティだけが残っている。 -delete myobj.a; -</pre> -<p><code>delete</code> を使用することでグローバル変数を削除することもできます。ただし、これは <code>var</code> キーワードを使用せずにその変数を宣言した場合のみです。</p> -<pre>g = 17; -delete g; -</pre> -<p>さらなる情報については <a href="/ja/Core_JavaScript_1.5_Guide/Operators/Special_Operators#delete" title="ja/Core_JavaScript_1.5_Guide/Operators/Special_Operators#delete">delete</a> をご覧ください。</p> -<p>{{PreviousNext("JavaScript/Guide/Creating_New_Objects/Defining_Getters_and_Setters", "JavaScript/Guide/Predefined_Core_Objects")}}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/index.html b/files/ja/web/javascript/guide/creating_new_objects/index.html deleted file mode 100644 index 0cbbc1753c..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: 新しいオブジェクトの作成 -slug: Web/JavaScript/Guide/Creating_New_Objects ---- -<h3 id=".E6.96.B0.E3.81.97.E3.81.84.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E4.BD.9C.E6.88.90" name=".E6.96.B0.E3.81.97.E3.81.84.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E4.BD.9C.E6.88.90">新しいオブジェクトの作成</h3> -<p>JavaScript には多くの定義済みオブジェクトがあります。さらに、自分でオブジェクトを作り出すことができます。JavaScript 1.2 以降では、オブジェクト初期化子を用いてオブジェクトを作成できます。もう 1 つの方法として、まずコンストラクタ関数を作成し、それからその関数と new 演算子を用いてオブジェクトのインスタンスを作成することもできます。</p> -<ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers">オブジェクト初期化子の使用</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_a_Constructor_Function" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_a_Constructor_Function">コンストラクタ関数の使用</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Indexing_Object_Properties" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Indexing_Object_Properties">オブジェクトのプロパティのインデックス付け</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Properties_for_an_Object_Type" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Properties_for_an_Object_Type">あるオブジェクトの種類に対するプロパティの定義</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Methods" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Methods">メソッドの定義</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_this_for_Object_References" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_this_for_Object_References">this を用いたオブジェクト参照</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Defining_Getters_and_Setters">ゲッタとセッタの定義</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Deleting_Properties" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Deleting_Properties">プロパティの削除</a></li> -</ul> -<p>{{ PreviousNext("JavaScript/Guide/Objects_and_Properties", "JavaScript/Guide/Creating_New_Objects/Using_Object_Initializers") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/indexing_object_properties/index.html b/files/ja/web/javascript/guide/creating_new_objects/indexing_object_properties/index.html deleted file mode 100644 index 024de85654..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/indexing_object_properties/index.html +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: オブジェクトのプロパティに対するインデックス付け -slug: Web/JavaScript/Guide/Creating_New_Objects/Indexing_Object_Properties ---- -<h3 id=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E3.82.A4.E3.83.B3.E3.83.87.E3.83.83.E3.82.AF.E3.82.B9.E4.BB.98.E3.81.91" name=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E3.82.A4.E3.83.B3.E3.83.87.E3.83.83.E3.82.AF.E3.82.B9.E4.BB.98.E3.81.91">オブジェクトのプロパティのインデックス付け</h3> -<p>JavaScript 1.0 では、オブジェクトのプロパティを、そのプロパティ名や順序のインデックスで参照できます。しかしながら、JavaScript 1.1 以降では、最初にプロパティをその名前で定義すると、常にその名前で参照しなければならず、また、最初にプロパティをインデックスで定義すると、常にそのインデックスで参照しなければなりません。</p> -<p>先の Car というオブジェクトの種類の例のようにコンストラクタ関数を用いてオブジェクトとそのプロパティを作成したとき、また、それぞれのプロパティを明示的に定義したとき(例:<code>myCar.color = "red"</code>)に、これは適用されます。そのため、<code>myCar{{ mediawiki.external(5) }} = "25 mpg"</code> のように、最初にインデックスを用いてオブジェクトのプロパティを定義した場合、<code>myCar{{ mediawiki.external(5) }}</code> のようにそのプロパティを後から参照できるようになります。</p> -<p>このルールの例外は、<code>forms</code> 配列のように HTML から反映されたオブジェクトです。これらの配列内のオブジェクトは、その順番を表す数(文書内のどこにあるかに基づく)か、またはその名前(定義されている場合)のどちらかで常に参照できます。例えば、文書内の 2 番目の <code><FORM></code> タグが "myForm" という <code>NAME</code> 属性を持っている場合、<code>document.forms{{ mediawiki.external(1) }}</code> や <code>document.forms{{ mediawiki.external('\"myForm\"') }}</code> や <code>document.myForm</code> とすることでそのフォームを参照できます。</p> -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects/Using_a_Constructor_Function", "JavaScript/Guide/Creating_New_Objects/Defining_Properties_for_an_Object_Type") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/using_a_constructor_function/index.html b/files/ja/web/javascript/guide/creating_new_objects/using_a_constructor_function/index.html deleted file mode 100644 index f3abc30e89..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/using_a_constructor_function/index.html +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: コンストラクタ関数の使用 -slug: Web/JavaScript/Guide/Creating_New_Objects/Using_a_Constructor_Function ---- -<h3 id=".E3.82.B3.E3.83.B3.E3.82.B9.E3.83.88.E3.83.A9.E3.82.AF.E3.82.BF.E9.96.A2.E6.95.B0.E3.81.AE.E4.BD.BF.E7.94.A8" name=".E3.82.B3.E3.83.B3.E3.82.B9.E3.83.88.E3.83.A9.E3.82.AF.E3.82.BF.E9.96.A2.E6.95.B0.E3.81.AE.E4.BD.BF.E7.94.A8">コンストラクタ関数の使用</h3> -<p>もう 1 つの方法として、次の 2 つのステップでオブジェクトを作成することができます。</p> -<ol> - <li>コンストラクタ関数を書くことでオブジェクトの種類を定義する。</li> - <li>new を用いてそのオブジェクトのインスタンスを作成する。</li> -</ol> -<p>オブジェクトの種類を定義するために、その名前、プロパティ、メソッドを定義する関数を作成する必要があります。例えば、車についてのオブジェクトの種類を作成したいとします。そしてこの種類のオブジェクトに <code>car</code> という名前を付け、make、model、および year というプロパティを持たせたいとします。こうするためには次のような関数を書きます。</p> -<pre>function car(make, model, year) { - this.make = make; - this.model = model; - this.year = year; -} -</pre> -<p>関数に渡された値に基づいてオブジェクトのプロパティに値を代入するために <code>this</code> を使用しています。</p> -<p>すると、次のようにして <code>mycar</code> というオブジェクトを作成することができるようになります。</p> -<pre>mycar = new car("Eagle", "Talon TSi", 1993); -</pre> -<p>この文は <code>mycar</code> を作成し、そのプロパティ用に指定した値を代入します。その結果、<code>mycar.make</code> の値は "Eagle" という文字列、<code>mycar.year</code> は 1993 という整数というようになります。</p> -<p><code>new</code> を呼び出すことで <code>car</code> オブジェクトをいくらでも作ることができます。</p> -<pre>kenscar = new car("Nissan", "300ZX", 1992); -vpgscar = new car("Mazda", "Miata", 1990); -</pre> -<p>それ自身別のオブジェクトであるというようなプロパティを持つオブジェクトを作ることができます。例えば、次のように <code>person</code> というオブジェクトを定義するとします。</p> -<pre>function person(name, age, sex) { - this.name = name; - this.age = age; - this.sex = sex; -} -</pre> -<p>そして、次のように 2 つの新しい person オブジェクトのインスタンスを作成します。</p> -<pre>rand = new person("Rand McKinnon", 33, "M"); -ken = new person("Ken Jones", 39, "M"); -</pre> -<p>次のようにして、car の定義を書き換えて、<code>person</code> オブジェクトをとる owner プロパティを持たせることができます。</p> -<pre>function car(make, model, year, owner) { - this.make = make; - this.model = model; - this.year = year; - this.owner = owner; -} -</pre> -<p>新しいオブジェクトのインスタンスを作成するために、次のようにします。</p> -<pre>car1 = new car("Eagle", "Talon TSi", 1993, rand); -car2 = new car("Nissan", "300ZX", 1992, ken); -</pre> -<p>新しいオブジェクトの作成時に文字列リテラルや整数値を渡す代わりに、上記の文ではオブジェクト <code>rand</code> および <code>ken</code> を所有者を表す引数として渡しています。car2 の所有者の名前を知りたい場合は次のプロパティにアクセスすることで可能になります。</p> -<pre>car2.owner.name -</pre> -<p>以前に定義したオブジェクトにいつでもプロパティを追加できることに注意してください。例えば次の文</p> -<pre>car1.color = "black" -</pre> -<p>はプロパティ <code>color</code> を car1 に追加し、それに "black" という値を代入します。しかしながら、この方法では他のどのオブジェクトにも影響を与えません。同じ種類の全オブジェクトに新しいプロパティを追加するには、そのプロパティを car というオブジェクトの種類の定義に追加する必要があります。</p> -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects/Using_Object_Initializers", "JavaScript/Guide/Creating_New_Objects/Indexing_Object_Properties") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/using_object_initializers/index.html b/files/ja/web/javascript/guide/creating_new_objects/using_object_initializers/index.html deleted file mode 100644 index 0a817b5407..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/using_object_initializers/index.html +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: オブジェクト初期化子の使用 -slug: Web/JavaScript/Guide/Creating_New_Objects/Using_Object_Initializers ---- -<h3 id=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E5.88.9D.E6.9C.9F.E5.8C.96.E5.AD.90.E3.81.AE.E4.BD.BF.E7.94.A8" name=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E5.88.9D.E6.9C.9F.E5.8C.96.E5.AD.90.E3.81.AE.E4.BD.BF.E7.94.A8">オブジェクト初期化子の使用</h3> -<p>コンストラクタ関数を使用してオブジェクトを作成する方法だけではなく、オブジェクト初期化子を使用してもオブジェクトを作成することができます。オブジェクト初期化子を使うことはリテラル表示を用いてオブジェクトを作成するということです。「オブジェクト初期化子」は C++ でも同じ意味で使用されている用語です。</p> -<p>オブジェクト初期化子を使用したオブジェクトの構文は次のとおりです。</p> -<pre class="eval">var obj = { property_1: value_1, // property_# は識別子でもよい - 2: value_2, // あるいは数値でもよい - ..., - "property_n": value_n }; // あるいは文字列でもよい -</pre> -<p>ここで、<code>obj</code> は新しいオブジェクトの名前を、各 <code>property_<em>i</em></code> は識別子(名前、数値、文字列リテラルのいずれか)を、各 <code>value_<em>i</em></code> はその値を <code>property_<em>i</em></code> に代入する式をそれぞれ表しています。<code>obj</code> および代入部分はなくてもかまいません。このオブジェクトを別の場所で参照する必要がないのであれば変数に代入する必要はありません。(文が期待されているところにオブジェクトリテラルを置く場合、リテラルを丸括弧で囲み、ブロック文と間違われないようにする必要があるかもしれません。)</p> -<p>トップレベルのスクリプトでオブジェクト初期化子を使用してオブジェクトを作成した場合、JavaScript はオブジェクトリテラルを含む式を評価するたびにそのオブジェクトを解釈します。さらに、関数内で使用された初期化子はその関数が呼び出されるたびに作成されます。</p> -<p>次の文は、式 cond が true の場合かつその場合に限り、あるオブジェクトを作成し、それを変数 <code>x</code> に代入します。</p> -<pre class="eval">if (cond) x = {hi:"there"}; -</pre> -<p>次の例は 3 つのプロパティを持つ <code>myHonda</code> を作成します。<code>engine</code> プロパティは自らもプロパティを持つオブジェクトでもあることに注意してください。</p> -<pre class="eval">myHonda = {color:"red",wheels:4,engine:{cylinders:4,size:2.2}}; -</pre> -<p>オブジェクト初期化子を使用して配列を作成することもできます。<a href="/ja/Core_JavaScript_1.5_Guide/Literals#.E9.85.8D.E5.88.97.E3.83.AA.E3.83.86.E3.83.A9.E3.83.AB" title="ja/Core_JavaScript_1.5_Guide/Literals#.E9.85.8D.E5.88.97.E3.83.AA.E3.83.86.E3.83.A9.E3.83.AB">配列リテラル</a> を参照してください。</p> -<p>JavaScript 1.1 以前ではオブジェクト初期化子を使用することはできません。コンストラクタ関数を使用するか、他のオブジェクトが備えているそのような用途の関数を使用しないとオブジェクトを作成できません。<a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_a_Constructor_Function" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_a_Constructor_Function">コンストラクタ関数の使用</a> をご覧ください。</p> -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects", "JavaScript/Guide/Creating_New_Objects/Using_a_Constructor_Function") }}</p> diff --git a/files/ja/web/javascript/guide/creating_new_objects/using_this_for_object_references/index.html b/files/ja/web/javascript/guide/creating_new_objects/using_this_for_object_references/index.html deleted file mode 100644 index 5fbd3b8aff..0000000000 --- a/files/ja/web/javascript/guide/creating_new_objects/using_this_for_object_references/index.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: this を用いたオブジェクト参照 -slug: Web/JavaScript/Guide/Creating_New_Objects/Using_this_for_Object_References ---- -<h3 id="this_.E3.82.92.E7.94.A8.E3.81.84.E3.81.9F.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E5.8F.82.E7.85.A7" name="this_.E3.82.92.E7.94.A8.E3.81.84.E3.81.9F.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E5.8F.82.E7.85.A7">this を用いたオブジェクト参照</h3> -<p>JavaScript にはカレントオブジェクトを参照するメソッド内で使用できる特殊なキーワード、this があります。例えば、あるオブジェクトの value プロパティの妥当性を確認する <code>validate</code> という関数があるとします。関数にはそのオブジェクトと、上限および下限の値を渡します。</p> -<pre>function validate(obj, lowval, hival) { - if ((obj.value < lowval) || (obj.value > hival)) - alert("Invalid Value!"); -} -</pre> -<p>各フォーム要素の <code>onchange</code> イベントハンドラにおいて <code>validate</code> を呼び出します。this を使うことで <code>form</code> 要素を渡すことができます。次の例をご覧ください。</p> -<pre><input type="text" name="age" size="3" - onChange="validate(this, 18, 99)"> -</pre> -<p>一般に <code>this</code> はあるメソッド内でそのメソッドを呼び出したオブジェクトを参照します。</p> -<p><code>form</code> プロパティと組み合わせることで、<code>this</code> はカレントオブジェクトの親のフォームを参照できます。次の例では、<code>myForm</code> というフォームに <code>Text</code> オブジェクトとボタンが格納されています。ユーザがボタンをクリックすると、<code>Text</code> オブジェクトの値にフォーム名がセットされます。ボタンの <code>onclick</code> イベントハンドラは <code>this.form</code> を利用して親のフォームである <code>myForm</code> を参照します。</p> -<pre><form name="myForm"> -<p><label>Form name:<input type="text" name="text1" value="Beluga"></label> -<p><input name="button1" type="button" value="Show Form Name" - onclick="this.form.text1.value=this.form.name"> -</p> -</form> -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Creating_New_Objects/Defining_Methods", "JavaScript/Guide/Creating_New_Objects/Defining_Getters_and_Setters") }}</p> diff --git a/files/ja/web/javascript/guide/expressions/index.html b/files/ja/web/javascript/guide/expressions/index.html deleted file mode 100644 index 4feb2b1aa8..0000000000 --- a/files/ja/web/javascript/guide/expressions/index.html +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: Expressions -slug: Web/JavaScript/Guide/Expressions ---- -<div>{{ 英語版章題("Expressions") }}</div> -<h2 id="式">式</h2> -<p><em>式</em>とは、リテラル、変数、演算子、そして単一の値に評価する式からなる有効なセットです。この値には数値、文字列、論理値が使用できます。</p> -<p>概念的に、式は 2 つの種類に分けることができます。ある値を変数に代入するものと、単純にある値を持つものです。例えば、<code>x = 7</code> という式は x に 7 という値を代入する式です。この式自体の評価結果は 7 です。このような式では<em>代入演算子</em>を用います。一方、<code>3 + 4</code> という式では単純に評価結果が 7 になります。この式は代入を行いません。このような式で用いられる演算子は単に<em>演算子</em>と呼ばれます。</p> -<p>JavaScript には以下の種類の式があります。</p> -<ul> - <li>算術式:数値に評価する。例えば 3.14159。(一般に <a href="/ja/Core_JavaScript_1.5_Guide/Operators/Arithmetic_Operators" title="ja/Core_JavaScript_1.5_Guide/Operators/Arithmetic_Operators">算術演算子</a> を使用)</li> - <li>文字列式:文字列に評価する。例えば "Fred" や "234"。(一般に <a href="/ja/Core_JavaScript_1.5_Guide/Operators/String_Operators" title="ja/Core_JavaScript_1.5_Guide/Operators/String_Operators">文字列演算子</a> を使用)</li> - <li>論理式:true または false に評価する。(よく <a href="/ja/Core_JavaScript_1.5_Guide/Operators/Logical_Operators" title="ja/Core_JavaScript_1.5_Guide/Operators/Logical_Operators">論理演算子</a> を用いる)</li> - <li>オブジェクト式:オブジェクトに評価する。(オブジェクトに評価するさまざまな例については <a href="/ja/Core_JavaScript_1.5_Guide/Operators/Special_Operators" title="ja/Core_JavaScript_1.5_Guide/Operators/Special_Operators">特殊演算子</a> を参照)</li> -</ul> -<p>{{ PreviousNext("JavaScript/Guide/Unicode", "JavaScript/Guide/Operators") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/break_statement/index.html b/files/ja/web/javascript/guide/loop_statements/break_statement/index.html deleted file mode 100644 index 35cc94abdf..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/break_statement/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: break 文 -slug: Web/JavaScript/Guide/Loop_Statements/break_Statement ---- -<h3 id="break_.E6.96.87" name="break_.E6.96.87">break 文</h3> -<p><code>break</code> 文は <code>loop</code> 文や <code>switch</code> 文、<code>label</code> 文から抜け出すために使用します。</p> -<ul> - <li><code>break</code> にラベルを使用しないと、最も内側にある <code>while</code> や <code>do-while</code>、<code>for</code>、<code>switch</code> から抜け、続く文にコントロールを移します。</li> - <li><code>break</code> にラベルを使用すると、指定されたラベルの付いた文から抜けます。</li> -</ul> -<p>break 文は次のように使用します。</p> -<ol> - <li><code>break;</code></li> - <li><code>break label;</code></li> -</ol> -<p>1番目の形式の構文は最も内側のループもしくは <code>switch</code> から抜けます。2番目の形式の構文は指定した label 文から抜けます。</p> -<p><strong>例</strong><br> - 次の例は、その値が <code>theValue</code> である要素のインデックスが見つかるまで、配列の要素について繰り返します。</p> -<pre>for (i = 0; i < a.length; i++) { - if (a[i] == theValue) - break; -} -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements/label_Statement", "JavaScript/Guide/Loop_Statements/continue_Statement") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/continue_statement/index.html b/files/ja/web/javascript/guide/loop_statements/continue_statement/index.html deleted file mode 100644 index f7a5697eeb..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/continue_statement/index.html +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: continue 文 -slug: Web/JavaScript/Guide/Loop_Statements/continue_Statement ---- -<h3 id="continue_.E6.96.87" name="continue_.E6.96.87">continue 文</h3> -<p><code>continue</code> 文は <code>while</code> 文、<code>do-while</code> 文、<code>for</code> 文、<code>label</code> 文をリスタートさせるために用います。</p> -<ul> - <li>ラベルを用いずに <code>continue</code> を使用した場合、現在繰り返している最も内側にある <code>while</code> 文 <code>do-while</code> 文、<code>for</code> 文を終了し、次の反復の実行に移ります。<code>break</code> 文とは異なり、<code>continue</code> はループ全体の実行を終了しません。<code>while</code> ループでは条件比較部分に戻ります。<code>for</code> ループではインクリメントの式に移ります。</li> - <li>ラベルを用いて <code>continue</code> を使用した場合、<code>label</code> で指定されたループ文に移ります。</li> -</ul> -<p><code>continue</code> 文は次のように使用します。</p> -<ol> - <li><code>continue</code></li> - <li><code>continue label</code></li> -</ol> -<p><strong>例 1</strong><br> - 次の例では、<code>i</code> の値が 3 のときに実行される <code>continue</code> 文を用いた <code>while</code> ループを示します。こうすることで <code>n</code> は順に 1、3、7、12 という値をとります。</p> -<pre class="eval">i = 0; -n = 0; -while (i < 5) { - i++; - if (i == 3) - continue; - n += i; -} -</pre> -<p><strong>例 2</strong><br> - <code>checkiandj</code> というラベルの付いた文の中に <code>checkj</code> というラベルの付いた文があります。<code>continue</code> に出くわすと、プログラムは <code>checkj</code> の現在の反復を終了し、次の反復を始めます。<code>continue</code> に出くわすたびに、条件が false になるまで <code>checkj</code> を繰り返します。false が返されると <code>checkiandj</code> 文の残りを完了し、条件が false を返すまで <code>checkiandj</code> を繰り返します。false が返されると <code>checkiandj</code> に続く文が実行されます。</p> -<p><code>continue</code> が <code>checkiandj</code> というラベルを持っているとプログラムは <code>checkiandj</code> 文の最初から続けます。</p> -<pre>checkiandj : - while (i < 4) { - document.write(i + "<br/>"); - i += 1; - checkj : - while (j > 4) { - document.write(j + "<br/>"); - j -= 1; - if ((j % 2) == 0) - continue checkj; - document.write(j + " is odd.<br/>"); - } - document.write("i = " + i + "<br/>"); - document.write("j = " + j + "<br/>"); - } -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements/break_Statement", "JavaScript/Guide/Object_Manipulation_Statements") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/do...while_statement/index.html b/files/ja/web/javascript/guide/loop_statements/do...while_statement/index.html deleted file mode 100644 index 6e1df1e586..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/do...while_statement/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: do...while 文 -slug: Web/JavaScript/Guide/Loop_Statements/do...while_Statement ---- -<h3 id="do...while_.E6.96.87" name="do...while_.E6.96.87">do...while 文</h3> -<p><code>do...while</code> 文は指定した条件が false に評価されるまで繰り返します。<code>do...while</code> 文は次のように使用します。</p> -<pre class="eval">do - statement -while (condition); -</pre> -<p><code>statement</code> は条件がチェックされる前に一度実行されます。複数の文を実行するにはブロック文 (<code>{ ... }</code>) を使用して文をグループ化してください。<code>condition</code> が true の場合、その文が再び実行されます。毎回実行された後に条件がチェックされます。条件が false ときは実行が停止され、コントロールが <code>do...while</code> の後に続く文に渡されます。</p> -<p><strong>例</strong><br> - 次の例では do ループは最低 1 回は反復され、i が 5 より小さくなくなるまで反復されます。</p> -<pre class="eval">do { - i += 1; - document.write(i); -} while (i < 5); -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements/for_Statement", "JavaScript/Guide/Loop_Statements/while_Statement") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/for_statement/index.html b/files/ja/web/javascript/guide/loop_statements/for_statement/index.html deleted file mode 100644 index b2dccec25b..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/for_statement/index.html +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: for 文 -slug: Web/JavaScript/Guide/Loop_Statements/for_Statement ---- -<h3 id="for_.E6.96.87" name="for_.E6.96.87">for 文</h3> -<p><code>for</code> ループは指定した条件が false に評価されるまで繰り返します。JavaScript の for ループは Java や C の for ループに似ています。<code>for</code> 文は次のように使用します。</p> -<pre class="eval">for ([initialExpression]; [condition]; [incrementExpression]) - statement -</pre> -<p><code>for</code> ループを実行すると以下のことが起こります。</p> -<ol> - <li>初期化式 <code>initialExpression</code> があれば実行されます。この式は通常、1 つかそれ以上のループカウンタを初期化しますが、構文的にはある程度複雑な式も指定できます。また、この式は変数を宣言することもできます。</li> - <li><code>condition</code> 式が評価されます。<code>condition</code> の値が true であればループ文が実行されます。<code>condition</code> が false の場合は <code>for</code> ループは終了します。<code>condition</code> 式が完全に省略されている場合、条件は true であると仮定されます。</li> - <li><code>statement</code> が実行されます。複数の式を実行するにはブロック文 (<code>{ ... }</code>) を使用して文をグループ化してください。</li> - <li>更新式 <code>incrementExpression</code> があれば実行されます。そしてコントロールがステップ 2 に戻ります。</li> -</ol> -<p><strong>例</strong><br> - 次の関数には、スクローリングリスト(複数選択できる Select オブジェクト)で選択されたオプションの数を数える <code>for</code> 文が含まれています。<code>for</code> 文では変数 <code>i</code> が宣言され、それが 0 に初期化されています。<code>i</code> が <code>Select</code> オブジェクトのオプションの個数より小さいかをチェックし、続く <code>if</code> 文を実行し、ループが 1 回りしたら <code>i</code> を 1 だけ増加させます。</p> -<pre><script type="text/javascript">//<![CDATA[ - -function howMany(selectObject) { - var numberSelected = 0; - for (var i = 0; i < selectObject.options.length; i++) { - if (selectObject.options[i].selected) - numberSelected++; - } - return numberSelected; -} - -//]]></script> -<form name="selectForm"> - <p> - <strong>Choose some music types, then click the button below:</strong> - <br/> - <select name="musicTypes" multiple="multiple"> - <option selected="selected">R&B</option> - <option>Jazz</option> - <option>Blues</option> - <option>New Age</option> - <option>Classical</option> - <option>Opera</option> - </select> - </p> - <p> - <input type="button" value="How many are selected?" - onclick="alert ('Number of options selected: ' + howMany(document.selectForm.musicTypes))"/> - </p> -</form> -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements", "JavaScript/Guide/Loop_Statements/do...while_Statement") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/index.html b/files/ja/web/javascript/guide/loop_statements/index.html deleted file mode 100644 index 54ef32d2c9..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: ループ文 -slug: Web/JavaScript/Guide/Loop_Statements ---- -<h2 id=".E3.83.AB.E3.83.BC.E3.83.97.E6.96.87" name=".E3.83.AB.E3.83.BC.E3.83.97.E6.96.87">ループ文</h2> -<p>ループは指定した条件が満たされている限り繰り返し実行されるコマンドのセットです。JavaScript は、label はもちろん、for、do while、while といったループ文をサポートしています(label 自体はループ文ではありませんが、これらの文とともに頻繁に使用されます)。さらに、<code>break</code> および <code>continue</code> 文をループ文の中で使うことができます。</p> -<p>さらに <code>for...in</code> 文も文を繰り返し実行しますが、これはオブジェクトの操作に使用します。<a href="/ja/Core_JavaScript_1.5_Guide/Object_Manipulation_Statements" title="ja/Core_JavaScript_1.5_Guide/Object_Manipulation_Statements">オブジェクト操作文</a> をご覧ください。</p> -<p>ループ文は以下のとおりです。</p> -<ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Loop_Statements/for_Statement" title="ja/Core_JavaScript_1.5_Guide/Loop_Statements/for_Statement">for 文</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Loop_Statements/do...while_Statement" title="ja/Core_JavaScript_1.5_Guide/Loop_Statements/do...while_Statement">do...while 文</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Loop_Statements/while_Statement" title="ja/Core_JavaScript_1.5_Guide/Loop_Statements/while_Statement">while 文</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Loop_Statements/label_Statement" title="ja/Core_JavaScript_1.5_Guide/Loop_Statements/label_Statement">label 文</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Loop_Statements/break_Statement" title="ja/Core_JavaScript_1.5_Guide/Loop_Statements/break_Statement">break 文</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Loop_Statements/continue_Statement" title="ja/Core_JavaScript_1.5_Guide/Loop_Statements/continue_Statement">continue 文</a></li> -</ul> -<p>{{ PreviousNext("JavaScript/Guide/Conditional_Statements", "JavaScript/Guide/Loop_Statements/for_Statement") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/label_statement/index.html b/files/ja/web/javascript/guide/loop_statements/label_statement/index.html deleted file mode 100644 index d0b878455b..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/label_statement/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: label 文 -slug: Web/JavaScript/Guide/Loop_Statements/label_Statement ---- -<h3 id="label_.E6.96.87" name="label_.E6.96.87">label 文</h3> -<p><code>label</code> を使うと、そのプログラムのどこからでも参照できる、識別子を持った文を作ることができます。例えば、ラベルを使用してあるループに名前を付けると、<code>break</code> 文や <code>continue</code> 文を使用してプログラムがループを脱出するべきかそのまま実行を継続するべきかを示すことができます。</p> -<p><code>label</code> 文は次のように使用します。</p> -<pre>label : - statement -</pre> -<p><code>label</code> の値は予約語でなければどんな JavaScript の識別子でも使用できます。ラベルを用いて名前を付ける <code>statement</code> はどんな文でも結構です。</p> -<p><strong>例</strong><br> - この例では <code>markLoop</code> というラベルを用いて while ループに名前を付けています。</p> -<pre>markLoop: -while (theMark == true) - doSomething(); -} -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements/while_Statement", "JavaScript/Guide/Loop_Statements/break_Statement") }}</p> diff --git a/files/ja/web/javascript/guide/loop_statements/while_statement/index.html b/files/ja/web/javascript/guide/loop_statements/while_statement/index.html deleted file mode 100644 index 77fd191f75..0000000000 --- a/files/ja/web/javascript/guide/loop_statements/while_statement/index.html +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: while 文 -slug: Web/JavaScript/Guide/Loop_Statements/while_Statement ---- -<h3 id="while_.E6.96.87" name="while_.E6.96.87">while 文</h3> -<p><code>while</code> 文は、指定した条件が true に評価される限り文を実行します。<code>while</code> 文は次のように使用します。</p> -<pre class="eval">while (condition) - statement -</pre> -<p>条件が false になるとループ内の <code>statement</code> の実行が停止し、ループの後に続く文にコントロールが渡されます。</p> -<p>ループの <code>statement</code> を実行する前に条件がテストされます。条件が true を返すと <code>statement</code> が実行され、再び条件がテストされます。条件が false を返すと、実行が停止され、<code>while</code> の後に続く文にコントロールが渡されます。</p> -<p>複数の文を実行するにはブロック文 ({ ... }) を用いて文をグループ化してください。</p> -<p><strong>例 1</strong><br> - 次の <code>while</code> ループでは <code>n</code> が 3 より小さい限り反復されます。</p> -<pre class="eval">n = 0; -x = 0; -while (n < 3) { - n++; - x += n; -} -</pre> -<p>それぞれの反復で、ループは <code>n</code> をインクリメントし、その値を <code>x</code> に加えています。その結果、<code>x</code> と <code>n</code> は次の値をとります。</p> -<ul> - <li>第 1 段階終了後:<code>n</code> = 1、<code>x</code> = 1</li> - <li>第 2 段階終了後:<code>n</code> = 2、<code>x</code> = 3</li> - <li>第 3 段階終了後:<code>n</code> = 3、<code>x</code> = 6</li> -</ul> -<p>第 3 段階が完了すると条件 <code>n</code> < 3 が true ではなくなっているため、ループは終了します。</p> -<p><strong>例 2</strong><br> - 無限ループは避けてください。ループの条件が最終的には false になることを確認してください。そうしないとループが終了しなくなります。次の <code>while</code> ループ内の文は永久に実行されます。条件が決して false にならないためです。</p> -<pre class="eval">while (true) { - alert("Hello, world"); -} -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements/do...while_Statement", "JavaScript/Guide/Loop_Statements/label_Statement") }}</p> diff --git a/files/ja/web/javascript/guide/object_manipulation_statements/index.html b/files/ja/web/javascript/guide/object_manipulation_statements/index.html deleted file mode 100644 index ddf781e031..0000000000 --- a/files/ja/web/javascript/guide/object_manipulation_statements/index.html +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: Object Manipulation Statements -slug: Web/JavaScript/Guide/Object_Manipulation_Statements ---- -<h3 id=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E6.93.8D.E4.BD.9C.E6.96.87" name=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E6.93.8D.E4.BD.9C.E6.96.87">オブジェクト操作文</h3> -<p>JavaScript はオブジェクトの操作に <code>for...in</code>、<code>for each...in</code> および <code>with</code> 文を使用します。</p> -<h4 id="for...in_.E6.96.87" name="for...in_.E6.96.87">for...in 文</h4> -<p><a href="/ja/Core_JavaScript_1.5_Reference/Statements/for...in" title="ja/Core_JavaScript_1.5_Reference/Statements/for...in"><code>for...in</code></a> 文は指定した変数をオブジェクトの全プロパティに対して反復します。それぞれのプロパティに対して JavaScript は指定した文を実行します。<code>for...in</code> 文は次のように使用します。</p> -<pre>for (variable in object) { - statements -} -</pre> -<p><strong>例</strong><br> - 次の関数は、あるオブジェクトとそのオブジェクトの名前を引数にとります。そしてそのオブジェクトの全プロパティに対して反復し、プロパティ名とその値のリストにした文字列を返します。</p> -<pre>function dump_props(obj, obj_name) { - var result = ""; - for (var i in obj) { - result += obj_name + "." + i + " = " + obj[i] + "<br>"; - } - result += "<hr>"; - return result; -} -</pre> -<p><code>make</code> および <code>model</code> というプロパティを持つ <code>car</code> というオブジェクトでは次のような結果が得られます。</p> -<pre class="eval">car.make = Ford -car.model = Mustang -</pre> -<p><strong>配列</strong><br> - <a href="/ja/Core_JavaScript_1.5_Reference/Global_Objects/Array" title="ja/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a> の要素に対して反復する方法としてこれを用いることは魅力的かもしれませんが、<strong>for...in</strong> 文はその配列の要素に加えてユーザ定義プロパティに対して繰り返すため、独自のプロパティやメソッドを追加するなどして Array オブジェクトに変更を加えると <strong>for...in</strong> 文は数値のインデックスに加えてユーザ定義プロパティの名前を返します。したがって、配列に対して反復したいときには数値のインデックスを用いた従来の <a href="/ja/Core_JavaScript_1.5_Reference/Statements/for" title="ja/Core_JavaScript_1.5_Reference/Statements/for">for</a> ループを使用したほうがいいでしょう。</p> -<h4 id="for_each...in_.E6.96.87" name="for_each...in_.E6.96.87">for each...in 文</h4> -<p><a href="/ja/Core_JavaScript_1.5_Reference/Statements/for_each...in" title="ja/Core_JavaScript_1.5_Reference/Statements/for_each...in"><code>for each...in</code></a> は <a href="/ja/New_in_JavaScript_1.6" title="ja/New_in_JavaScript_1.6">JavaScript 1.6</a> で導入されるループ文です。これは <code>for...in</code> に似ていますが、オブジェクトのプロパティの名前ではなく、プロパティの値に対して反復します。</p> -<h4 id="with_.E6.96.87" name="with_.E6.96.87">with 文</h4> -<p><a href="/ja/Core_JavaScript_1.5_Reference/Statements/with" title="ja/Core_JavaScript_1.5_Reference/Statements/with"><code>with</code></a> 文はデフォルトのオブジェクトについて文のセットを実行します。JavaScript はその文のセットにおいて非修飾名を検索し、その名前がデフォルトのオブジェクトのプロパティであるかを決定します。非修飾名がプロパティにマッチすると、そのプロパティがその文で使われます。そうでない場合はローカル変数かグローバル変数が使われます。</p> -<p><code>with</code> 文は次のように使用します。</p> -<pre>with (object) { - statements -} -</pre> -<p><strong>例</strong><br> - 次の <code>with</code> 文では <code>Math</code> オブジェクトがデフォルトのオブジェクトに指定されています。<code>with</code> 文内の文は <code>PI</code> プロパティや <code>cos</code> および <code>sin</code> メソッドを参照していますが、オブジェクトは指定していません。JavaScript はこれらの参照は <code>Math</code> オブジェクトへのものであると想定します。</p> -<pre>var a, x, y; -var r = 10; -with (Math) { - a = PI * r * r; - x = r * cos(PI); - y = r * sin(PI/2); -} -</pre> -<p>注意:<code>with</code> 文を使うことでプログラムをより簡潔にすることができますが、<code>with</code> の不適切な使用はプログラムを大幅にスローダウンさせることに繋がります。<a href="/ja/Core_JavaScript_1.5_Reference/Statements/with" title="ja/Core_JavaScript_1.5_Reference/Statements/with">Core JavaScript 1.5 Reference:Statements:with</a> を参照してください。</p> - -<p>{{ PreviousNext("JavaScript/Guide/Loop_Statements/continue_Statement", "JavaScript/Guide/Comments") }}</p> diff --git a/files/ja/web/javascript/guide/objects_and_properties/index.html b/files/ja/web/javascript/guide/objects_and_properties/index.html deleted file mode 100644 index f2679c1d00..0000000000 --- a/files/ja/web/javascript/guide/objects_and_properties/index.html +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: オブジェクトとプロパティ -slug: Web/JavaScript/Guide/Objects_and_Properties ---- -<h3 id=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.A8.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3" name=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.A8.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3">オブジェクトとプロパティ</h3> -<p>JavaScript のオブジェクトには、それに結びつけられたプロパティがあります。簡単な記法でオブジェクトのプロパティにアクセスできます。</p> -<pre>objectName.propertyName -</pre> -<p>オブジェクト名もプロパティ名も大文字と小文字を区別します。プロパティの定義は、そのプロパティに値を代入することで行います。例えば、<code>myCar</code> という名前のオブジェクトがあるとします(今回はオブジェクトが既に存在していると仮定)。次のようにして、そのオブジェクトに <code>make</code>、<code>model</code>、<code>year</code> という名前のプロパティをそれぞれ作成することができます。</p> -<pre>myCar.make = "Ford"; -myCar.model = "Mustang"; -myCar.year = 1969; -</pre> -<p>配列はある単一の変数名に結びつけられた値の順序集合です。JavaScript におけるプロパティと配列は密接に関連しています。事実、それらは同一のデータ構造への異なるインタフェースなのです。そのため、例えば次のようにして <code>myCar</code> オブジェクトのプロパティにアクセスすることができます。</p> -<pre>myCar["make"] = "Ford"; -myCar["model"] = "Mustang"; -myCar["year"] = 1969; -</pre> -<p>この手の配列は<em>連想配列</em>として知られています。それぞれのインデックスの要素が文字列にも結びつけられているからです。これがどう動作するかというと、次の関数は引数としてオブジェクトとそのオブジェクトの名前を渡すとオブジェクトのプロパティを表示します。</p> -<pre>function show_props(obj, obj_name) { - var result = ""; - for (var i in obj) - result += obj_name + "." + i + " = " + obj[i] + "\n"; - return result; -} -</pre> -<p>関数 <code>show_props(myCar, "myCar")</code> を呼び出すと以下の結果が返されます。</p> -<pre>myCar.make = Ford -myCar.model = Mustang -myCar.year = 1969 -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Predefined_Functions/escape_and_unescape_Functions", "JavaScript/Guide/Creating_New_Objects") }}</p> diff --git a/files/ja/web/javascript/guide/obsolete_pages/index.html b/files/ja/web/javascript/guide/obsolete_pages/index.html deleted file mode 100644 index 88bf9acbe7..0000000000 --- a/files/ja/web/javascript/guide/obsolete_pages/index.html +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Obsolete Pages -slug: Web/JavaScript/Guide/Obsolete_Pages -translation_of: Web/JavaScript/Guide -translation_of_original: Web/JavaScript/Guide/Obsolete_Pages ---- -<p>This is a list of pages that have been merged into chapters (in alphabetical order):</p> - - -<div>{{tree}}</div> diff --git a/files/ja/web/javascript/guide/obsolete_pages/predefined_core_objects/function_object/index.html b/files/ja/web/javascript/guide/obsolete_pages/predefined_core_objects/function_object/index.html deleted file mode 100644 index 79c30b670a..0000000000 --- a/files/ja/web/javascript/guide/obsolete_pages/predefined_core_objects/function_object/index.html +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: Function Object -slug: Web/JavaScript/Guide/Obsolete_Pages/Predefined_Core_Objects/Function_Object ---- -<p> </p> -<h3 id="Function_.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88" name="Function_.E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88">Function オブジェクト</h3> -<p>定義済みの <code>Function</code> オブジェクトは、関数としてコンパイルさせたい JavaScript コードの文字列を指定します。</p> -<p><code>Function</code> オブジェクトを作成するには次のようにします。</p> -<pre>functionObjectName = new Function ([arg1, arg2, ... argn], functionBody) -</pre> -<p><code>functionObjectName</code> は変数名または既存のオブジェクトのプロパティ名です。オブジェクトに小文字のイベントハンドラ名を続けて、<code>window.onerror</code> のようにして指定することもできます。</p> -<p><code>arg1</code>, <code>arg2</code>, ... <code>argn</code> は関数が仮引数名として使用する引数です。それぞれが JavaScript の識別子として妥当な文字列である必要があります。例えば、"x" や "theForm" などです。</p> -<p><code>functionBody</code> は関数の本体としてコンパイルさせたい JavaScript コードを表す文字列です。</p> -<p><code>Function</code> オブジェクトはそれが使用されるたびに評価されます。これは関数を宣言し、それをコード内で呼び出す方法よりも非効率的です。宣言された関数はコンパイルされるからです。</p> -<p>ここで説明した関数の定義方法に加えて、<code>function</code> 文と関数式を用いることもできます。詳しくは <a href="/ja/Core_JavaScript_1.5_Reference" title="ja/Core_JavaScript_1.5_Reference">コア JavaScript 1.5 リファレンス</a> を参照してください。</p> -<p>次のコードは関数を変数 <code>setBGColor</code> に代入します。この関数は開いている文書の背景色をセットします。</p> -<pre>var setBGColor = new Function("document.bgColor='antiquewhite'") -</pre> -<p><code>Function</code> オブジェクトを呼び出すには、それがあたかも関数であるかのように変数名を指定すればいいのです。次のコードは <code>setBGColor</code> 変数で指定された関数を実行します。</p> -<pre>var colorChoice="antiquewhite" -if (colorChoice=="antiquewhite") {setBGColor()} -</pre> -<p>次のどちらかの方法を使用することでイベントハンドラに関数を代入することができます。</p> -<pre>1. document.form1.colorButton.onclick=setBGColor -2. <INPUT NAME="colorButton" TYPE="button" - VALUE="Change background color" - onClick="setBGColor()"> -</pre> -<p>上記の変数 <code>setBGColor</code> を作成することは次の関数を宣言することと同じようなことです。</p> -<pre>function setBGColor() { - document.bgColor='antiquewhite' -} -</pre> -<p>関数を変数に代入することは関数を宣言することと似ていますが、異なる点もあります。</p> -<ul> - <li><code>var setBGColor = new Function("...")</code> のようにして関数を変数に代入すると、<code>setBGColor</code> は <code>new Function()</code> を用いて作成した関数への参照がその値であるような変数になります。</li> - <li><code>function setBGColor() {...}</code> のようにして関数を作成すると、<code>setBGColor</code> は変数ではなく関数の名前になります。</li> -</ul> -<p>関数を関数の中に入れ子にすることができます。内側の関数は外側の関数に対してプライベートになります。</p> -<ul> - <li>内側の関数には外側の関数の文からしかアクセスできません。</li> - <li>内側の関数は外側の関数の引数や変数を使用できます。外側の関数は内側の関数の引数や変数を使用できません。</li> -</ul> -<p>{{ PreviousNext("Core_JavaScript_1.5_Guide:Predefined_Core_Objects:Date_Object", "Core_JavaScript_1.5_Guide:Predefined_Core_Objects:Math_Object") }}</p> diff --git a/files/ja/web/javascript/guide/operators/arithmetic_operators/index.html b/files/ja/web/javascript/guide/operators/arithmetic_operators/index.html deleted file mode 100644 index 4aa9662292..0000000000 --- a/files/ja/web/javascript/guide/operators/arithmetic_operators/index.html +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: 算術演算子 -slug: Web/JavaScript/Guide/Operators/Arithmetic_Operators ---- -<h3 id=".E7.AE.97.E8.A1.93.E6.BC.94.E7.AE.97.E5.AD.90" name=".E7.AE.97.E8.A1.93.E6.BC.94.E7.AE.97.E5.AD.90">算術演算子</h3> -<p>算術演算子は、そのオペランドに数値(リテラルか変数)をとり、1 つの数値を返します。標準的な算術演算子は、加算 (+)、減算 (-)、乗算 (*)、除算 (/) です。これらの演算子は他のほとんどのプログラミング言語と同じように機能しますが、そのときの数値は、浮動小数点数として扱われます(0 で除算した結果は、<a href="/ja/Core_JavaScript_1.5_Reference/Global_Properties/NaN" title="ja/Core_JavaScript_1.5_Reference/Global_Properties/NaN"><code>NaN</code></a> になることにも注意してください)。</p> -<pre>1 / 2 // JavaScript では 0.5 を返す -1 / 2 // Java では 0 を返す(どちらの数も浮動小数点数として明記されていない) - -1.0 / 2.0 // JavaScript でも Java でも 0.5 を返す -</pre> -<p>さらに、JavaScript では以下の表で示された算術演算子も使用できます。</p> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>演算子</th> - <th>説明</th> - <th>例</th> - </tr> - <tr> - <td>%<br> - (モジュロ)</td> - <td>2 項演算子。2 つのオペランドで除算したときの整数の余りを返す。</td> - <td>12 % 5 は 2 を返す。</td> - </tr> - <tr> - <td>++<br> - (インクリメント)</td> - <td>単項演算子。オペランドに 1 を加える。前置演算子 (++x) を使った場合、オペランドに 1 を加えた後にその値を返す。後置演算子 (x++) を使った場合、オペランドに 1 を加える前にその値を返す。</td> - <td><code>x</code> が 3 のとき、<code>++x</code> は <code>x</code> に 4 をセットし、4 を返す。一方、<code>x++</code> は <code>x</code> に 4 をセットし、3 を返す。</td> - </tr> - <tr> - <td>--<br> - (デクリメント)</td> - <td>単項演算子。オペランドから 1 を引く。戻り値はインクリメント演算子のものと同様。</td> - <td><code>x</code> が 3 のとき、<code>--x</code> は <code>x</code> に 2 をセットし、2 を返す。一方、<code>x--</code> は <code>x</code> に 2 をセットし、3 を返す。</td> - </tr> - <tr> - <td>-<br> - (符号反転)</td> - <td>単項演算子。オペランドの符号を反転してその値を返す。</td> - <td><code>x</code> が 3 のとき、<code>-x</code> は -3 を返す。</td> - </tr> - </tbody> -</table> -<p><small><strong>表 3.4:算術演算子</strong></small></p> -<p>{{ PreviousNext("JavaScript/Guide/Operators/Comparison_Operators", "JavaScript/Guide/Operators/Bitwise_Operators") }}</p> diff --git a/files/ja/web/javascript/guide/operators/assignment_operators/index.html b/files/ja/web/javascript/guide/operators/assignment_operators/index.html deleted file mode 100644 index 88a0b0beb7..0000000000 --- a/files/ja/web/javascript/guide/operators/assignment_operators/index.html +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: 代入演算子 -slug: Web/JavaScript/Guide/Operators/Assignment_Operators ---- -<h3 id=".E4.BB.A3.E5.85.A5.E6.BC.94.E7.AE.97.E5.AD.90" name=".E4.BB.A3.E5.85.A5.E6.BC.94.E7.AE.97.E5.AD.90">代入演算子</h3> -<p>代入演算子は、右のオペランドの値に基づいた値を左のオペランドに代入します。基本的な代入演算子はイコール (=) ですが、これは右のオペランドの値を左のオペランドに代入します。すなわち、x = y では y の値を x に代入します。</p> -<p>他の代入演算子は標準的な演算をするための短縮表記があります。次の表でそれを示します。</p> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>短縮表記した演算子</th> - <th>意味</th> - </tr> - <tr> - <td>x += y</td> - <td>x = x + y</td> - </tr> - <tr> - <td>x -= y</td> - <td>x = x - y</td> - </tr> - <tr> - <td>x *= y</td> - <td>x = x * y</td> - </tr> - <tr> - <td>x /= y</td> - <td>x = x / y</td> - </tr> - <tr> - <td>x %= y</td> - <td>x = x % y</td> - </tr> - <tr> - <td>x <<= y</td> - <td>x = x << y</td> - </tr> - <tr> - <td>x >>= y</td> - <td>x = x >> y</td> - </tr> - <tr> - <td>x >>>= y</td> - <td>x = x >>> y</td> - </tr> - <tr> - <td>x &= y</td> - <td>x = x & y</td> - </tr> - <tr> - <td>x ^= y</td> - <td>x = x ^ y</td> - </tr> - <tr> - <td>x |= y</td> - <td>x = x | y</td> - </tr> - </tbody> -</table> -<p><small><strong>表 3.2:代入演算子</strong></small></p> -<p>{{ PreviousNext("JavaScript/Guide/Operators", "JavaScript/Guide/Operators/Comparison_Operators") }}</p> diff --git a/files/ja/web/javascript/guide/operators/comparison_operators/index.html b/files/ja/web/javascript/guide/operators/comparison_operators/index.html deleted file mode 100644 index 182802bb5a..0000000000 --- a/files/ja/web/javascript/guide/operators/comparison_operators/index.html +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: 比較演算子 -slug: Web/JavaScript/Guide/Operators/Comparison_Operators ---- -<h3 id=".E6.AF.94.E8.BC.83.E6.BC.94.E7.AE.97.E5.AD.90" name=".E6.AF.94.E8.BC.83.E6.BC.94.E7.AE.97.E5.AD.90">比較演算子</h3> -<p><span class="comment">This seems to me kind of poorly explained, mostly the diference betwen "==" and "==="...</span> 比較演算子は、オペランドを比較し、比較結果に基づいた論理値を返します。オペランドには数値、文字列、論理値、オブジェクトが使用できます。文字列は、Unicode 値を用いて標準的な辞書順に基づいて比較されます。ほとんどの場合、2 つのオペランドが異なる型ならば JavaScript はそのオペランドを比較に適した型に変換しようとします(このルールの唯一の例外は <code>===</code> および <code>!==</code> であり、これらは厳密に等値か否かを判断し、等値性をチェックする前にオペランドを適合する型に変換するということはありません)。これは一般に数値の比較が実行されることになります。次の表では比較演算子について説明します。次のコードで考えます。</p> -<pre class="eval">var var1 = 3, var2 = 4; -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>演算子</th> - <th>説明</th> - <th>true を返す例</th> - </tr> - <tr> - <td>等しい (==)</td> - <td>オペランドが等しい場合に true を返す。</td> - <td><code>3 == var1</code><br> - <p><code>"3" == var1</code></p> - <code>3 == '3'</code></td> - </tr> - <tr> - <td>等しくない (!=)</td> - <td>オペランドが等しくない場合に true を返す。</td> - <td><code>var1 != 4<br> - var2 != "3"</code></td> - </tr> - <tr> - <td>厳密に等しい (===)</td> - <td>オペランドが等しく、かつ同じ型である場合に true を返す。</td> - <td><code>3 === var1</code></td> - </tr> - <tr> - <td>厳密には等しくない (!==)</td> - <td>オペランドが等しくなく、かつ/または同じ型でない場合に true を返す。</td> - <td><code>var1 !== "3"<br> - 3 !== '3'</code></td> - </tr> - <tr> - <td>より大きい (>)</td> - <td>左のオペランドが右のオペランドよりも大きい場合に true を返す。</td> - <td><code>var2 > var1<br> - "12" > 2</code></td> - </tr> - <tr> - <td>以上 (>=)</td> - <td>左のオペランドが右のオペランド以上である場合に true を返す。</td> - <td><code>var2 >= var1<br> - var1 >= 3</code></td> - </tr> - <tr> - <td>より小さい (<)</td> - <td>左のオペランドが右のオペランドよりも小さい場合に true を返す。</td> - <td><code>var1 < var2<br> - "12" < "2"</code></td> - </tr> - <tr> - <td>以下 (<=)</td> - <td>左のオペランドが右のオペランド以下である場合に true を返す。</td> - <td><code>var1 <= var2<br> - var2 <= 5</code></td> - </tr> - </tbody> -</table> -<p><small><strong>表 3.3:比較演算子</strong></small></p> -<p>{{ PreviousNext("JavaScript/Guide/Operators/Assignment_Operators", "JavaScript/Guide/Operators/Arithmetic_Operators")}}</p> diff --git a/files/ja/web/javascript/guide/operators/logical_operators/index.html b/files/ja/web/javascript/guide/operators/logical_operators/index.html deleted file mode 100644 index fa6fa08068..0000000000 --- a/files/ja/web/javascript/guide/operators/logical_operators/index.html +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: 論理演算子 -slug: Web/JavaScript/Guide/Operators/Logical_Operators ---- -<h3 id=".E8.AB.96.E7.90.86.E6.BC.94.E7.AE.97.E5.AD.90" name=".E8.AB.96.E7.90.86.E6.BC.94.E7.AE.97.E5.AD.90">論理演算子</h3> -<p>論理演算子では基本的に真偽(論理)値を用います。そのような値があると真偽値を返します。しかし、&& および || 演算子は実際には指定されたオペランドの一方の値を返します。そのため、非真偽値とともに論理演算子が使われると非真偽値を返します。論理演算子について次の表で説明します。</p> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>演算子</th> - <th>使用法</th> - <th>説明</th> - </tr> - <tr> - <td>&&</td> - <td>expr1 && expr2</td> - <td>(論理 AND)expr1 を false と見ることができる場合は expr1 を返す。そうでない場合は expr2 を返す。したがって、真偽値が使われた場合、両オペランドが true の場合は && は true を返し、そうでない場合は false を返す。</td> - </tr> - <tr> - <td>||</td> - <td>expr1 || expr2</td> - <td>(論理 OR)expr1 を true と見ることができる場合は expr1 を返す。そうでない場合は expr2 を返す。したがって、真偽値が使われた場合、どちらかのオペランドが true の場合は || は true を返し、両方とも false の場合は false を返す。</td> - </tr> - <tr> - <td>!</td> - <td>!expr</td> - <td>(論理 NOT)オペランドを true と見ることができる場合は false を返す。そうでない場合は true を返す。</td> - </tr> - </tbody> -</table> -<p><small><strong>表 3.7:論理演算子</strong></small></p> -<p>false と見ることができる式とは、null、0、空文字列 ("")、または undefined に評価される式のことです。</p> -<p>以下のコードで &&(論理 AND)演算子の例を示します。</p> -<pre>a1=true && true // t && t は true を返す -a2=true && false // t && f は false を返す -a3=false && true // f && t は false を返す -a4=false && (3 == 4) // f && f は false を返す -a5="Cat" && "Dog" // t && t は Dog を返す -a6=false && "Cat" // f && t は false を返す -a7="Cat" && false // t && f は false を返す -</pre> -<p>以下のコードで ||(論理 OR)演算子の例を示します。</p> -<pre>o1=true || true // t || t は true を返す -o2=false || true // f || t は true を返す -o3=true || false // t || f は true を返す -o4=false || (3 == 4) // f || f は false を返す -o5="Cat" || "Dog" // t || t は Cat を返す -o6=false || "Cat" // f || t は Cat を返す -o7="Cat" || false // t || f は Cat を返す -</pre> -<p>以下のコードで !(論理 NOT)演算子の例を示します。</p> -<pre>n1=!true // !t は false を返す -n2=!false // !f は true を返す -n3=!"Cat" // !t は false を返す -</pre> -<h4 id=".E3.82.B7.E3.83.A7.E3.83.BC.E3.83.88.E3.82.B5.E3.83.BC.E3.82.AD.E3.83.83.E3.83.88.E8.A9.95.E4.BE.A1" name=".E3.82.B7.E3.83.A7.E3.83.BC.E3.83.88.E3.82.B5.E3.83.BC.E3.82.AD.E3.83.83.E3.83.88.E8.A9.95.E4.BE.A1">ショートサーキット評価</h4> -<p>論理式は左から右に評価されるため、以下のルールを用いることで「ショートサーキット」評価ができるようになっています。</p> -<ul> - <li><code>false</code> && <em>anything</em> は false にショートサーキット評価する。</li> - <li><code>true</code> || <em>anything</em> は true ショートサーキット評価する。</li> -</ul> -<p>論理のルールはこれらの評価が常に正確であることを保証しています。上記の式の <em>anything</em> の部分は評価されないため、何らかの副作用が生じないように注意してください。</p> -<p>{{ PreviousNext("JavaScript/Guide/Operators/Bitwise_Operators", "JavaScript/Guide/Operators/String_Operators") }}</p> diff --git a/files/ja/web/javascript/guide/operators/special_operators/index.html b/files/ja/web/javascript/guide/operators/special_operators/index.html deleted file mode 100644 index 226faf2b3c..0000000000 --- a/files/ja/web/javascript/guide/operators/special_operators/index.html +++ /dev/null @@ -1,197 +0,0 @@ ---- -title: 特殊演算子 -slug: Web/JavaScript/Guide/Operators/Special_Operators ---- -<h3 id=".E7.89.B9.E6.AE.8A.E6.BC.94.E7.AE.97.E5.AD.90" name=".E7.89.B9.E6.AE.8A.E6.BC.94.E7.AE.97.E5.AD.90">特殊演算子</h3> -<p>JavaScript は以下の特殊演算子があります。</p> -<ul> - <li>{{ Anch("条件演算子") }}</li> - <li>{{ Anch("コンマ演算子") }}</li> - <li>{{ Anch("delete") }}</li> - <li>{{ Anch("in") }}</li> - <li>{{ Anch("instanceof") }}</li> - <li>{{ Anch("new") }}</li> - <li>{{ Anch("this") }}</li> - <li>{{ Anch("typeof") }}</li> - <li>{{ Anch("void") }}</li> -</ul> -<h4 id=".E6.9D.A1.E4.BB.B6.E6.BC.94.E7.AE.97.E5.AD.90" name=".E6.9D.A1.E4.BB.B6.E6.BC.94.E7.AE.97.E5.AD.90">条件演算子</h4> -<p>条件演算子は JavaScript では唯一の 3 つのオペランドをとる演算子です。演算子は条件に基づいて 2 つの値のうち、1 つを選択します。構文は次のとおりです。</p> -<pre>condition ? val1 : val2 -</pre> -<p><code>condition</code> が true の場合、演算子は <code>val1</code> の値を選択します。そうでない場合は <code>val2</code> の値を選択します。標準的な演算子が使用できる場所でならどこででも条件演算子を使用することができます。</p> -<p>例えば、</p> -<pre>status = (age >= 18) ? "adult" : "minor" -</pre> -<p>この文では、<code>age</code> が 18 以上の場合 "adult" という値を変数 <code>status</code> に代入します。そうでない場合は "minor" という値を <code>status</code> に代入します。</p> -<h4 id=".E3.82.B3.E3.83.B3.E3.83.9E.E6.BC.94.E7.AE.97.E5.AD.90" name=".E3.82.B3.E3.83.B3.E3.83.9E.E6.BC.94.E7.AE.97.E5.AD.90">コンマ演算子</h4> -<p>コンマ演算子 (,) は単に両方のオペランドを評価し、第 2 のオペランドの値を返します。この演算子は主に <code>for</code> ループ内で使用されます。このことでループのたびに複数の変数を更新できるようになります。</p> -<p>例えば、a が一辺が 10 要素の 2 次元配列のとき、以下のコードではコンマ演算子を用いることで 2 変数を同時にインクリメントしています。このコードでは配列の対角成分の値を出力します。</p> -<pre>for (var i=0, j=9; i <= 9; i++, j--) - document.writeln("a["+i+"]["+j+"]= " + a[i][j]) -</pre> -<h4 id="delete" name="delete">delete</h4> -<p>delete 演算子はオブジェクトやオブジェクトのプロパティ、配列の指定されたインデックスの要素を削除します。構文は以下のとおりです。</p> -<pre>delete objectName -delete objectName.property -delete objectName[index] -delete property // with 文内でのみ有効 -</pre> -<p>ここで、<code>objectName</code> はオブジェクトの名前を、<code>property</code> は既存のプロパティを、<code>index</code> は配列の要素の位置を表す整数をそれぞれ表しています。</p> -<p>4 番目の形式は <code>with</code> 文内でのみ有効で、これはあるオブジェクトからプロパティを削除します。</p> -<p><code>delete</code> 演算子を使うことで暗黙的に宣言された変数を削除することができますが、<code>var</code> 文を用いて宣言された変数は削除できません。</p> -<p><code>delete</code> 演算子が成功すると、そのプロパティや要素には <code>undefined</code> がセットされます。また、演算が可能な場合は <code>delete</code> 演算子は true を返します。演算が不可能な場合は false を返します。</p> -<pre>x=42 -var y= 43 -myobj=new Number() -myobj.h=4 // プロパティ h を作成 -delete x // true を返す(暗黙的に宣言されているならば削除可能) -delete y // false を返す(var 付きで宣言されているなら削除不可能) -delete Math.PI // false を返す(定義済みプロパティは削除不可能) -delete myobj.h // true を返す(ユーザ定義プロパティは削除可能) -delete myobj // true を返す(暗黙的に宣言されているならば削除可能) -</pre> -<p><strong>配列要素の削除</strong><br> - 配列要素を削除したとき、配列の長さには影響を及ぼしません。例えば a{{ mediawiki.external(3) }} を削除したとき、a{{ mediawiki.external(4) }} は依然 a{{ mediawiki.external(4) }} のままで、a{{ mediawiki.external(3) }} は undefined になります。</p> -<p><code>delete</code> 演算子で配列要素を除去すると、もうその要素はその配列からなくなります。次の例では tree{{ mediawiki.external(3) }} は <code>delete</code> によって除去されます。</p> -<pre>trees=new Array("redwood","bay","cedar","oak","maple") -delete trees[3] -if (3 in trees) { - // ここは実行されない -} -</pre> -<p>配列要素は存在させたいが、値は未定義にしたいという場合は、<code>delete</code> 演算子の代わりに <code>undefined</code> キーワードを使用してください。次の例では <code>trees{{ mediawiki.external(3) }}</code> には <code>undefined</code> という値が代入されますが、その配列要素は存在したままになります。</p> -<pre>trees=new Array("redwood","bay","cedar","oak","maple") -trees[3]=undefined -if (3 in trees) { - // ここは実行される -} -</pre> -<h4 id="in" name="in">in</h4> -<p><code>in</code> 演算子は、指定されたプロパティが指定されたオブジェクトにある場合に true を返します。構文は以下のとおりです。</p> -<pre>propNameOrNumber in objectName -</pre> -<p>ここで、<code>propNameOrNumber</code> はプロパティ名か配列のインデックスを表す文字列式または数値式を、<code>objectName</code> はオブジェクトの名前をそれぞれ表しています。</p> -<p>次の例では <code>in</code> 演算子の使用法を示します。</p> -<pre>// 配列 -trees=new Array("redwood","bay","cedar","oak","maple") -0 in trees // true を返す -3 in trees // true を返す -6 in trees // false を返す -"bay" in trees // false を返す(インデックスの指す値ではなく、 - // インデックスの数字を指定しなければならない) -"length" in trees // true を返す(length は Array のプロパティ) - -// 定義済みオブジェクト -"PI" in Math // true を返す -myString=new String("coral") -"length" in myString // true を返す - -// ユーザ定義オブジェクト -mycar = {make:"Honda",model:"Accord",year:1998} -"make" in mycar // true を返す -"model" in mycar // true を返す -</pre> -<h4 id="instanceof" name="instanceof">instanceof</h4> -<p><code>instanceof</code> 演算子は、指定されたオブジェクトが指定されたオブジェクトの種類である場合に true を返します。構文は次のとおりです。</p> -<pre>objectName instanceof objectType -</pre> -<p>ここで、<code>objectName</code> は <code>objectType</code> と比較するオブジェクトの名前を、<code>objectType</code> は <code>Date</code> や <code>Array</code> のようなオブジェクトの種類をそれぞれ表しています。</p> -<p>実行時にオブジェクトの種類を確認する必要があるときは <code>instanceof</code> を使用してください。例えば、例外を受け取るとき、投げられた例外の種類によって別々の例外を扱うコードに分岐させることができます。</p> -<p>例えば、次のコードでは <code>instanceof</code> を使用することで <code>theDay</code> が <code>Date</code> オブジェクトであるかどうかを決定しています。<code>theDay</code> は <code>Date</code> オブジェクトなので <code>if</code> 文の中の文は実行されます。</p> -<pre>theDay=new Date(1995, 12, 17) -if (theDay instanceof Date) { - // 実行される文 -} -</pre> -<h4 id="new" name="new">new</h4> -<p><code>new</code> 演算子は、ユーザ定義オブジェクトや、<code>Array</code>、<code>Boolean</code>、<code>Date</code>、<code>Function</code>、<code>Image</code>、<code>Number</code>、<code>Object</code>、<code>Option</code>、<code>RegExp</code>、<code>String</code> といった定義済みオブジェクトのインスタンスを作成するのに使用します。サーバでは <code>DbPool</code>、<code>Lock</code>、<code>File</code>、<code>SendMail</code> といったオブジェクトも使用できます。<code>new</code> の使用法は以下のとおりです。</p> -<pre>objectName = new objectType ( param1 [,param2] ...[,paramN] ) -</pre> -<p>オブジェクト初期化子を使用してもオブジェクトを作成することができます。<a href="/ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers" title="ja/Core_JavaScript_1.5_Guide/Creating_New_Objects/Using_Object_Initializers">オブジェクト初期化子の使用</a> にて説明しています。</p> -<p>詳しくはコア JavaScript リファレンスの <a href="/ja/Core_JavaScript_1.5_Reference/Operators/Special_Operators/new_Operator" title="ja/Core_JavaScript_1.5_Reference/Operators/Special_Operators/new_Operator">new 演算子</a> のページを参照してください。</p> -<h4 id="this" name="this">this</h4> -<p><code>this</code> キーワードを使うことでカレントオブジェクトを参照することができます。一般に <code>this</code> はあるメソッド内でそのメソッドを呼び出したオブジェクトを参照します。使用法は以下のとおりです。</p> -<pre>this[.propertyName] -</pre> -<p><strong>例 1</strong><br> - あるオブジェクトの <code>value</code> プロパティの妥当性を確認する <code>validate</code> という関数を想定します。関数にはそのオブジェクトと、上限および下限の値を渡します。</p> -<pre>function validate(obj, lowval, hival) { - if ((obj.value < lowval) || (obj.value > hival)) - alert("Invalid Value!") -} -</pre> -<p>各フォーム要素の <code>onChange</code> イベントハンドラにおいて <code>validate</code> を呼び出します。<code>this</code> を使うことでフォーム要素を渡すことができます。次の例をご覧ください。</p> -<pre><B>Enter a number between 18 and 99:</B> -<INPUT TYPE = "text" NAME = "age" SIZE = 3 - onChange="validate(this, 18, 99)"> -</pre> -<p><strong>例 2</strong><br> - <code>form</code> プロパティと組み合わせると <code>this</code> でカレントオブジェクトの親のフォームを参照できます。次の例では、<code>myForm</code> というフォームに <code>Text</code> オブジェクトとボタンが格納されています。ユーザがボタンをクリックすると、<code>Text</code> オブジェクトの値にフォーム名がセットされます。ボタンの <code>onClick</code> イベントハンドラは <code>this.form</code> を利用して親のフォームである <code>myForm</code> を参照します。</p> -<pre><FORM NAME="myForm"> -Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga"> -<P> -<INPUT NAME="button1" TYPE="button" VALUE="Show Form Name" - onClick="this.form.text1.value=this.form.name"> -</FORM> -</pre> -<h4 id="typeof" name="typeof">typeof</h4> -<p><code>typeof</code> 演算子は次の方法のうち、どちらかの方法で使用します。</p> -<pre>1. typeof operand -2. typeof (operand) -</pre> -<p><code>typeof</code> 演算子は、未評価のオペランドの型を指す文字列を返します。<code>operand</code> は返される型を調べる対象となる文字列、変数、キーワード、オブジェクトです。括弧はあってもなくてもかまいません。</p> -<p>以下の変数を定義することを想定します。</p> -<pre>var myFun = new Function("5+2") -var shape="round" -var size=1 -var today=new Date() -</pre> -<p><code>typeof</code> 演算子はこれらの変数に対して以下の結果を返します。</p> -<pre>typeof myFun is function -typeof shape is string -typeof size is number -typeof today is object -typeof dontExist is undefined -</pre> -<p><code>true</code> や <code>null</code> というキーワードに対して、<code>typeof</code> 演算子は以下の結果を返します。</p> -<pre>typeof true is boolean -typeof null is object -</pre> -<p>数値や文字列に対して、<code>typeof</code> 演算子は以下の結果を返します。</p> -<pre>typeof 62 is number -typeof 'Hello world' is string -</pre> -<p>プロパティ値に対して、<code>typeof</code> 演算子はプロパティ値の型を返します。</p> -<pre>typeof document.lastModified is string -typeof window.length is number -typeof Math.LN2 is number -</pre> -<p>メソッドや関数に対して、<code>typeof</code> 演算子は以下の結果を返します。</p> -<pre>typeof blur is function -typeof eval is function -typeof parseInt is function -typeof shape.split is function -</pre> -<p>定義済みオブジェクトに対して、<code>typeof</code> 演算子は以下の結果を返します。</p> -<pre>typeof Date is function -typeof Function is function -typeof Math is function -typeof Option is function -typeof String is function -</pre> -<h4 id="void" name="void">void</h4> -<p><code>void</code> 演算子は次の方法のうち、どちらかの方法で使用します。</p> -<pre>1. void (expression) -2. void expression -</pre> -<p><code>void</code> 演算子は値を返さずに評価する式を指定します。<code>expression</code> は評価する JavaScript の式です。式の周りの括弧はあってもなくてもかまいませんが、使用したほうが見た目はいいです。</p> -<p><code>void</code> 演算子を使用することで式をハイパーテキストリンクとして指定することができます。式は評価されますが、開いている文書の代わりに読み込まれるということはありません。</p> -<p>以下のコードはユーザがクリックしても何も起こらないハイパーテキストリンクを作成します。ユーザがリンクをクリックすると <code>void(0)</code> は undefined に評価され、JavaScript としては影響を及ぼしません。</p> -<pre><A HREF="javascript:void(0)">Click here to do nothing</A> -</pre> -<p>以下のコードはユーザがクリックするとフォームが送信されるハイパーテキストリンクを作成します。</p> -<pre><A HREF="javascript:void(document.form.submit())"> -Click here to submit</A> -</pre> -<p>{{ PreviousNext("JavaScript/Guide/Operators/String_Operators", "JavaScript/Guide/Creating_a_Regular_Expression") }}</p> diff --git a/files/ja/web/javascript/guide/operators/string_operators/index.html b/files/ja/web/javascript/guide/operators/string_operators/index.html deleted file mode 100644 index 41bf8bbc44..0000000000 --- a/files/ja/web/javascript/guide/operators/string_operators/index.html +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: 文字列演算子 -slug: Web/JavaScript/Guide/Operators/String_Operators ---- -<h2 id=".E6.96.87.E5.AD.97.E5.88.97.E6.BC.94.E7.AE.97.E5.AD.90" name=".E6.96.87.E5.AD.97.E5.88.97.E6.BC.94.E7.AE.97.E5.AD.90">文字列演算子</h2> -<p>比較演算子は文字列に使用できますが、これに加えて 2 つの文字列を結合する結合演算子 (+) も使用できます。これは 2 つのオペランドの文字列を結合した文字列を返します。例えば、<code>"my " + "string"</code> は <code>"my string"</code> という文字列を返します。</p> -<p>短縮表記した代入演算子 += も文字列の結合に使用できます。例えば、変数 <code>mystring</code> に "alpha" という値が格納されているとき、式 <code>mystring += "bet"</code> の評価結果は "alphabet" となり、この値を <code>mystring</code> に代入します。</p> -<p>{{ PreviousNext("JavaScript/Guide/Operators/Logical_Operators", "JavaScript/Guide/Operators/Special_Operators") }}</p> diff --git a/files/ja/web/javascript/guide/predefined_functions/escape_and_unescape_functions/index.html b/files/ja/web/javascript/guide/predefined_functions/escape_and_unescape_functions/index.html deleted file mode 100644 index aecb8a81f1..0000000000 --- a/files/ja/web/javascript/guide/predefined_functions/escape_and_unescape_functions/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: escape 関数と unescape 関数 -slug: Web/JavaScript/Guide/Predefined_Functions/escape_and_unescape_Functions ---- -<div class="onlyinclude"> - <h3 id="escape_.E3.81.8A.E3.82.88.E3.81.B3_unescape_.E9.96.A2.E6.95.B0" name="escape_.E3.81.8A.E3.82.88.E3.81.B3_unescape_.E9.96.A2.E6.95.B0">escape および unescape 関数</h3> - <p><code>escape</code> および <code>unescape</code> 関数は文字列をエンコードしたりデコードしたりします。<code>escape</code> 関数は ISO Latin 文字セットで表された引数の 16 進エンコーディングを返します。<code>unescape</code> は指定した 16 進エンコーディングの値に対する ASCII 文字列を返します。</p> - <p>これらの関数の構文は以下のとおりです。</p> - <pre>escape(string) -unescape(string) -</pre> - <p>これらの関数は主にサーバサイド JavaScript で URL 中の名前と値のペアのエンコードやデコードに使用されます。</p> - <code>escape</code> および <code>unescape</code> 関数は 非 ASCII 文字に対しては正しく機能せず、廃止予定になっています。JavaScript 1.5 以降では <code><a href="/ja/Core_JavaScript_1.5_Reference/Global_Functions/encodeURI" title="ja/Core_JavaScript_1.5_Reference/Global_Functions/encodeURI">encodeURI</a></code>、<code><a href="/ja/Core_JavaScript_1.5_Reference/Global_Functions/decodeURI" title="ja/Core_JavaScript_1.5_Reference/Global_Functions/decodeURI">decodeURI</a></code>、<code><a href="/ja/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent" title="ja/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent">encodeURIComponent</a></code> および <code><a href="/ja/Core_JavaScript_1.5_Reference/Global_Functions/decodeURIComponent" title="ja/Core_JavaScript_1.5_Reference/Global_Functions/decodeURIComponent">decodeURIComponent</a></code> を使用してください。</div> -<p>{{ PreviousNext("JavaScript/Guide/Predefined_Functions/Number_and_String_Functions", "JavaScript/Guide/Objects_and_Properties") }}</p> diff --git a/files/ja/web/javascript/guide/predefined_functions/eval_function/index.html b/files/ja/web/javascript/guide/predefined_functions/eval_function/index.html deleted file mode 100644 index 3945955e86..0000000000 --- a/files/ja/web/javascript/guide/predefined_functions/eval_function/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: eval 関数 -slug: Web/JavaScript/Guide/Predefined_Functions/eval_Function ---- -<div class="onlyinclude"> - <h3 id="eval_.E9.96.A2.E6.95.B0" name="eval_.E9.96.A2.E6.95.B0">eval 関数</h3> - <p><code>eval</code> 関数は JavaScript のコードの文字列を特定のオブジェクトを参照することなく評価します。eval の構文は次のとおりです。</p> - <pre>eval(expr) -</pre> - <p>ここで <code>expr</code> は評価される文字列です。</p> - 文字列が式を表している場合は <code>eval</code> はその式を評価します。また、1 つ以上の JavaScript の文を表している場合は eval はその式を実行します。<code>eval</code> のコードのスコープは呼び出し元コードのスコープと同じです。演算式を評価するために <code>eval</code> を呼び出さないでください。JavaScript は自動的に演算式を評価します。</div> -<p>{{ PreviousNext("JavaScript/Guide/Predefined_Functions", "JavaScript/Guide/Predefined_Functions/isFinite_Function") }}</p> diff --git a/files/ja/web/javascript/guide/predefined_functions/index.html b/files/ja/web/javascript/guide/predefined_functions/index.html deleted file mode 100644 index 758c6f22a0..0000000000 --- a/files/ja/web/javascript/guide/predefined_functions/index.html +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: 定義済み関数 -slug: Web/JavaScript/Guide/Predefined_Functions ---- -<div class="onlyinclude"> - <h3 id=".E5.AE.9A.E7.BE.A9.E6.B8.88.E3.81.BF.E9.96.A2.E6.95.B0" name=".E5.AE.9A.E7.BE.A9.E6.B8.88.E3.81.BF.E9.96.A2.E6.95.B0">定義済み関数</h3> - <p>JavaScript にはトップレベルの定義済み関数がいくつかあります。</p> - <ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Predefined_Functions/eval_Function" title="ja/Core_JavaScript_1.5_Guide/Predefined_Functions/eval_Function">eval</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Predefined_Functions/isFinite_Function" title="ja/Core_JavaScript_1.5_Guide/Predefined_Functions/isFinite_Function">isFinite</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Predefined_Functions/isNaN_Function" title="ja/Core_JavaScript_1.5_Guide/Predefined_Functions/isNaN_Function">isNaN</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Predefined_Functions/parseInt_and_parseFloat_Functions" title="ja/Core_JavaScript_1.5_Guide/Predefined_Functions/parseInt_and_parseFloat_Functions">parseInt と parseFloat</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Predefined_Functions/Number_and_String_Functions" title="ja/Core_JavaScript_1.5_Guide/Predefined_Functions/Number_and_String_Functions">Number と String</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/Predefined_Functions/escape_and_unescape_Functions" title="ja/Core_JavaScript_1.5_Guide/Predefined_Functions/escape_and_unescape_Functions">encodeURI と decodeURI、encodeURIComponent、decodeURIComponent(すべて Javascript 1.5 以降で使用可能)</a></li> - </ul> -</div> -<p>{{ PreviousNext("JavaScript/Guide/Using_the_arguments_object", "JavaScript/Guide/Predefined_Functions/eval_Function") }}</p> diff --git a/files/ja/web/javascript/guide/the_employee_example/creating_the_hierarchy/index.html b/files/ja/web/javascript/guide/the_employee_example/creating_the_hierarchy/index.html deleted file mode 100644 index 2340536ff7..0000000000 --- a/files/ja/web/javascript/guide/the_employee_example/creating_the_hierarchy/index.html +++ /dev/null @@ -1,134 +0,0 @@ ---- -title: Creating the Hierarchy -slug: Web/JavaScript/Guide/The_Employee_Example/Creating_the_Hierarchy ---- -<h3 id=".E9.9A.8E.E5.B1.A4.E3.81.AE.E4.BD.9C.E6.88.90" name=".E9.9A.8E.E5.B1.A4.E3.81.AE.E4.BD.9C.E6.88.90">階層の作成</h3> -<p>Employee の階層を実装するための適当なコンストラクタ関数を定義する方法はいくつかあります。これの定義に何を選択するかは、アプリケーションで何ができるようにしたいかに大きくよります。</p> -<p>このセクションではとても単純(かつ比較的柔軟でない)定義の使用方法を示し、継承を機能させる方法を実際に示します。これらの定義では、オブジェクト作成時に何らかのプロパティの値を指定することはできません。新しく作成されるオブジェクトは単にデフォルトの値を取得するだけです。これは後から変更できます。図 8.2 ではこれらの単純な定義を備えた階層を例示します。</p> -<p>実際のアプリケーションでは、オブジェクト作成時にプロパティの値を設定できるようにするコンストラクタを定義することになるでしょう(詳しくは <a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/More_Flexible_Constructors" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/More_Flexible_Constructors">より柔軟なコンストラクタ</a> を参照)。今回はこれらの単純な定義を使用して、継承はどのようにして起こるのかを実際に示していくことにします。</p> -<p><img alt="Image:hier02.gif" class="internal" src="/@api/deki/files/1905/=Hier02.gif"><br> - <small><strong>図 8.2:Employee オブジェクトの定義</strong></small></p> -<p>以下に示すように、Java と JavaScript の <code>Employee</code> の定義は似ています。唯一の相違点は、Java では各プロパティに対して型を指定する必要があるのに対して、JavaScript ではその必要がないことです。また、Java のクラスでは明示的なコンストラクタメソッドを作成する必要があります。</p> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>JavaScript</th> - <th>Java</th> - </tr> - <tr> - <td> - <pre> -function Employee () { -this.name = ""; -this.dept = "general"; -} -</pre> - </td> - <td> - <pre> -public class Employee { - public String name; - public String dept; - public Employee () { - this.name = ""; - this.dept = "general"; - } -} -</pre> - </td> - </tr> - </tbody> -</table> -<p><code>Manager</code> および <code>WorkerBee</code> の定義では、継承の連鎖において上である次のオブジェクトの指定方法に違いがあります。JavaScript では原型的なインスタンスをコンストラクタ関数の <code>prototype</code> プロパティとして追加します。コンストラクタを定義した後ならいつでもそれをすることができます。Java ではクラス定義内でスーパークラスを指定します。クラス定義の外部でスーパークラスを変更することはできません。</p> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>JavaScript</th> - <th>Java</th> - </tr> - <tr> - <td> - <pre> -function Manager () { -this.reports = []; -} -Manager.prototype = new Employee; - -function WorkerBee () { -this.projects = []; -} -WorkerBee.prototype = new Employee; -</pre> - </td> - <td> - <pre> -public class Manager extends Employee { - public Employee[] reports; - public Manager () { - this.reports = new Employee[0]; - } -} - -public class WorkerBee extends Employee { - public String[] projects; - public WorkerBee () { - this.projects = new String[0]; - } -} -</pre> - </td> - </tr> - </tbody> -</table> -<p><code>Engineer</code> および <code>SalesPerson</code> の定義は、<code>WorkerBee</code> の子孫、それゆえに <code>Employee</code> の子孫であるオブジェクトを作成します。これらの種類のオブジェクトは連鎖において上にある全オブジェクトのプロパティを持ちます。さらに、これらの定義は <code>dept</code> プロパティの継承された値をこれらのオブジェクト固有の新しい値で上書きします。</p> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>JavaScript</th> - <th>Java</th> - </tr> - <tr> - <td> - <pre> -function SalesPerson () { - this.dept = "sales"; - this.quota = 100; -} -SalesPerson.prototype = new WorkerBee; - -function Engineer () { - this.dept = "engineering"; - this.machine = ""; -} -Engineer.prototype = new WorkerBee; -</pre> - </td> - <td> - <pre> -public class SalesPerson extends WorkerBee { - public double quota; - public SalesPerson () { - this.dept = "sales"; - this.quota = 100.0; - } -} - -public class Engineer extends WorkerBee { - public String machine; - public Engineer () { - this.dept = "engineering"; - this.machine = ""; - } -} -</pre> - </td> - </tr> - </tbody> -</table> -<p>これらの定義を使用して、そのプロパティのデフォルト値を取得するこれらのオブジェクトのインスタンスを作成することができます。図 8.3 ではこれらの JavaScript の定義を使用して新しいオブジェクトを作成する方法を示しています。また、新しいオブジェクトに対するプロパティの値も示しています。</p> -<p><strong>注意</strong>:<em>インスタンス</em>という用語はクラスベース言語においてはある特定の技術的な意味を持っています。これらの言語では、インスタンスとはクラスの個々のメンバであり、クラスとは根本的に異なるものです。JavaScript では「インスタンス」はこの技術的な意味を持っていません。なぜならば JavaScript にはクラスとインスタンスとの間のこの違いがないからです。しかしながら、JavaScript について話す際に、「インスタンス」をある特定のコンストラクタ関数を用いて作成したオブジェクトを意味する言葉として正式ではない形で使用することがあります。例えば、<code>jane</code> は <code>Engineer</code> のインスタンスであると砕けた言い方をすることもできます。同様に、<em>親</em>、<em>子</em>、<em>祖先</em>、そして<em>子孫</em>という用語は JavaScript において正式な意味を持ちませんが、プロトタイプチェーンにおいて上や下にあるオブジェクトについて言及する際にそれらを正式ではない形で使用してもかまいません。</p> -<p><img alt="Image:hier03.gif" class="internal" src="/@api/deki/files/1906/=Hier03.gif"><br> - <small><strong>図 8.3:単純な定義を用いたオブジェクトの作成</strong></small></p> -<div class="noinclude"> - <p>{{ PreviousNext("Core_JavaScript_1.5_Guide:The_Employee_Example", "Core_JavaScript_1.5_Guide:The_Employee_Example:Object_Properties") }}</p> -</div> diff --git a/files/ja/web/javascript/guide/the_employee_example/index.html b/files/ja/web/javascript/guide/the_employee_example/index.html deleted file mode 100644 index 63176fa7e2..0000000000 --- a/files/ja/web/javascript/guide/the_employee_example/index.html +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: The Employee Example -slug: Web/JavaScript/Guide/The_Employee_Example ---- -<h3 id=".E5.BE.93.E6.A5.AD.E5.93.A1.E3.81.AE.E4.BE.8B" name=".E5.BE.93.E6.A5.AD.E5.93.A1.E3.81.AE.E4.BE.8B">従業員の例</h3> -<p>この章の残りは次の図で示す従業員の階層を使用していきます。</p> -<p><img alt="Image:hier01.gif" class="internal" src="/@api/deki/files/1904/=Hier01.gif"></p> -<p><small><strong>図 8.1:単純なオブジェクト階層</strong></small></p> -<p>これの例では以下のオブジェクトを使用しています。</p> -<ul> - <li>Employee はプロパティ name(デフォルトの値は空文字列)および dept(デフォルトの値は "general")を持つ。</li> - <li>Manager は Employee をベースとしている。これは reports プロパティ(デフォルトの値は空の配列、その値として Employee オブジェクトの配列を持たせる)を追加する。</li> - <li>WorkerBee も Employee をベースとしている。これは projects プロパティ(デフォルトの値は空の配列、その値として文字列の配列を持たせる)を追加する。</li> - <li>SalesPerson は WorkerBee をベースとしている。これは quota プロパティ(デフォルトの値は 100)を追加する。さらに dept プロパティを "sales" という値で上書きする。これは販売員は全員同じ部署に所属していることを示す。</li> - <li>Engineer は WorkerBee をベースとしている。これは machine プロパティ(デフォルトの値は空文字列)を追加し、さらに dept プロパティを "engineering" という値で上書きする。</li> -</ul> -<p>残りの例:</p> -<ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Creating_the_Hierarchy" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Creating_the_Hierarchy">階層の作成</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties">オブジェクトのプロパティ</a> - <ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Inheriting_Properties" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Inheriting_Properties">プロパティの継承</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Adding_Properties" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Adding_Properties">プロパティの追加</a></li> - </ul> - </li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/More_Flexible_Constructors" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/More_Flexible_Constructors">より柔軟なコンストラクタ</a></li> -</ul> -<div class="noinclude"> - <p>{{ PreviousNext("Core_JavaScript_1.5_Guide:Class-Based_vs._Prototype-Based_Languages", "Core_JavaScript_1.5_Guide:The_Employee_Example:Creating_the_Hierarchy") }}</p> -</div> -<p> </p> diff --git a/files/ja/web/javascript/guide/the_employee_example/object_properties/adding_properties/index.html b/files/ja/web/javascript/guide/the_employee_example/object_properties/adding_properties/index.html deleted file mode 100644 index c6d536602b..0000000000 --- a/files/ja/web/javascript/guide/the_employee_example/object_properties/adding_properties/index.html +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Adding Properties -slug: Web/JavaScript/Guide/The_Employee_Example/Object_Properties/Adding_Properties ---- -<h3 id=".E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E8.BF.BD.E5.8A.A0" name=".E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E8.BF.BD.E5.8A.A0">プロパティの追加</h3> -<p>JavaScript では実行時にどんなオブジェクトにもプロパティを追加することができます。コンストラクタ関数で与えられるプロパティだけを使う必要はありません。ある 1 つのオブジェクト固有のプロパティを追加するには、次のようにしてオブジェクトに値を代入します。</p> -<pre>mark.bonus = 3000; -</pre> -<p>すると、<code>mark</code> オブジェクトには bonus プロパティができます。しかし、他のどの <code>WorkerBee</code> にもこのプロパティは存在しません。</p> -<p>あるコンストラクタ関数に対するプロトタイプとして使用されているオブジェクトに新しいプロパティを追加する場合、プロトタイプからプロパティを継承する全オブジェクトへそのプロパティを追加することになります。例えば、次の文を使用すると <code>specialty</code> プロパティをすべての従業員に対して追加することができます。</p> -<pre>Employee.prototype.specialty = "none"; -</pre> -<p>JavaScript がこの文を実行するとすぐに <code>mark</code> オブジェクトも "<code>none</code>" という値を持つ specialty プロパティを持つようになります。次の図ではこのプロパティを Employee プロトタイプに追加し、さらに <code>Engineer</code> プロトタイプに対するそれを上書きしたときの効果を示します。</p> -<p><img alt="Image:hier04.gif" class="internal" src="/@api/deki/files/1907/=Hier04.gif"><br> - <small><strong>図 8.4:プロパティの追加</strong></small></p> -<div class="noinclude"> - <p>{{ PreviousNext("Core_JavaScript_1.5_Guide:The_Employee_Example:Object_Properties:Inheriting_Properties", "Core_JavaScript_1.5_Guide:The_Employee_Example:More_Flexible_Constructors") }}</p> -</div> -<p> </p> diff --git a/files/ja/web/javascript/guide/the_employee_example/object_properties/index.html b/files/ja/web/javascript/guide/the_employee_example/object_properties/index.html deleted file mode 100644 index e529b8bb52..0000000000 --- a/files/ja/web/javascript/guide/the_employee_example/object_properties/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: Object Properties -slug: Web/JavaScript/Guide/The_Employee_Example/Object_Properties ---- -<h3 id=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3" name=".E3.82.AA.E3.83.96.E3.82.B8.E3.82.A7.E3.82.AF.E3.83.88.E3.81.AE.E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3">オブジェクトのプロパティ</h3> -<p>このセクションでは、プロトタイプチェーンにおいてオブジェクトが他のオブジェクトからどのようにプロパティを継承するのか、また、実行時にプロパティを追加すると何が起きるのかについて論じます。</p> -<ul> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Inheriting_Properties" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Inheriting_Properties">プロパティの継承</a></li> - <li><a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Adding_Properties" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Object_Properties/Adding_Properties">プロパティの追加</a></li> -</ul> -<div class="noinclude"> - <p>{{ PreviousNext("Core_JavaScript_1.5_Guide:The_Employee_Example:Creating_the_Hierarchy", "Core_JavaScript_1.5_Guide:The_Employee_Example:Object_Properties:Inheriting_Properties") }}</p> -</div> diff --git a/files/ja/web/javascript/guide/the_employee_example/object_properties/inheriting_properties/index.html b/files/ja/web/javascript/guide/the_employee_example/object_properties/inheriting_properties/index.html deleted file mode 100644 index 798746ead6..0000000000 --- a/files/ja/web/javascript/guide/the_employee_example/object_properties/inheriting_properties/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Inheriting Properties -slug: >- - Web/JavaScript/Guide/The_Employee_Example/Object_Properties/Inheriting_Properties ---- -<h3 id=".E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E7.B6.99.E6.89.BF" name=".E3.83.97.E3.83.AD.E3.83.91.E3.83.86.E3.82.A3.E3.81.AE.E7.B6.99.E6.89.BF">プロパティの継承</h3> -<p>次の文を用いて(<a href="/ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Creating_the_Hierarchy" title="ja/Core_JavaScript_1.5_Guide/The_Employee_Example/Creating_the_Hierarchy">図 8.3</a> で示したように)<code>mark</code> オブジェクトを <code>WorkerBee</code> として作成するとします。</p> -<pre class="eval">mark = new WorkerBee; -</pre> -<p>JavaScript は new 演算子に出くわすと、新しく汎用オブジェクトを生成し、この新しいオブジェクトを <code>this</code> キーワードの値として WorkerBee コンストラクタ関数に渡します。コンストラクタ関数は明示的に <code>projects</code> プロパティの値をセットします。さらに、内部的な <code>__proto__</code> プロパティの値として <code>WorkerBee.prototype</code> の値をセットします。(このプロパティ名は最初と最後に 2 文字ずつのアンダースコアが付いています。)<code>__proto__</code> プロパティはプロパティの値を返すのに使用されるプロトタイプチェーンを決定します。これらのプロパティがセットされると JavaScript は新しいオブジェクトを返し、代入文は変数 <code>mark</code> にそのオブジェクトをセットします。</p> -<p>このプロセスでは <code>mark</code> がプロトタイプチェーンから継承するプロパティとして明示的には <code>mark</code> オブジェクトに値(<em>ローカルの</em>値)を格納しません。プロパティの値を使用するとき、JavaScript はまずその値がそのオブジェクトに存在しているかどうかを確認します。存在している場合はその値が返されます。値がローカルには存在していない場合、JavaScript はプロトタイプチェーンを確認します(<code>__proto__</code> プロパティを使用)。プロトタイプチェーン内のオブジェクトがそのプロパティの値を持っている場合、その値が返されます。そのようなプロパティが見つからない場合は JavaScript はそのオブジェクトにはそのプロパティがないと報告します。このようにして、<code>mark</code> オブジェクトには次のようなプロパティと値が入ることになります。</p> -<pre class="eval">mark.name = ""; -mark.dept = "general"; -mark.projects = []; -</pre> -<p><code>mark</code> オブジェクトは <code>mark.__proto__</code> の原型的なオブジェクトから name および dept プロパティの値を継承します。WorkerBee コンストラクタによって projects プロパティにローカルの値が代入されます。このことでプロパティとその値を継承することができます。このプロセスの細かいところは <a href="/ja/Core_JavaScript_1.5_Guide/Property_Inheritance_Revisited" title="ja/Core_JavaScript_1.5_Guide/Property_Inheritance_Revisited">プロパティの継承、再び</a> にて議論します。</p> -<p>これらのコンストラクタにインスタンス固有の値を渡せないため、この情報は汎用的になります。プロパティの値は WorkerBee によって作成されるすべての新しいオブジェクトに共有される、デフォルトの値になります。もちろん、これらのどのプロパティのでもその値を変えることができます。そのためには次のようにして <code>mark</code> に固有の情報を与えます。</p> -<pre class="eval">mark.name = "Doe, Mark"; -mark.dept = "admin"; -mark.projects = ["navigator"]; -</pre> -<div class="noinclude"> - <p>{{ PreviousNext("Core JavaScript 1.5 Guide:The Employee Example:Object Properties", "Core JavaScript 1.5 Guide:The Employee Example:Object Properties:Adding Properties") }}</p> -</div> diff --git a/files/ja/web/javascript/guide/using_the_arguments_object/index.html b/files/ja/web/javascript/guide/using_the_arguments_object/index.html deleted file mode 100644 index 10c2d9e3ff..0000000000 --- a/files/ja/web/javascript/guide/using_the_arguments_object/index.html +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: arguments オブジェクトの使用 -slug: Web/JavaScript/Guide/Using_the_arguments_object ---- -<div class="onlyinclude"> - <h3 id="arguments_オブジェクトの使用"><code>arguments</code> オブジェクトの使用</h3> - <p>関数の引数は配列のようなオブジェクトで管理されます。関数内では、次のようにして渡された引数を指すことができます。</p> - <pre class="eval">arguments[i] -</pre> - <p>ここで <code>i</code> は引数の順序を表す数を指します。これは 0 から始まります。関数に渡された第 1 引数は <code>arguments{{ mediawiki.external(0) }}</code> となります。引数のトータルの数は <code>arguments.length</code> で示されます。</p> - <p><code>arguments</code> オブジェクトを使用すると、宣言時の仮引数の数よりも多くの引数を使って関数を呼び出すことができます。これはその関数に渡す引数の数が前もってわかっていない場合に役立ちます。<code>arguments</code>.length を使用することで実際にその関数に渡された引数の数を特定することができます。また、<code>arguments</code> オブジェクトを使用することで各引数を扱うことができます。</p> - <p>例えば、複数の文字列を連結する関数を考えます。この関数の仮引数は、連結するアイテムを区切るのに用いる文字列のみです。この関数は次のように定義されています。</p> - <pre class="eval">function myConcat(separator) { - var result = ""; // リストを初期化する - // 引数について繰り返し - for (var i = 1; i < arguments.length; i++) { - result += arguments[i] + separator; - } - return result; -} -</pre> - <p>この関数に引数をいくつも渡すことができます。そして各引数を文字列のリストに連結します。</p> - <pre class="eval">// "red, orange, blue, " を返す -myConcat(", ", "red", "orange", "blue"); - -// "elephant; giraffe; lion; cheetah; " を返す -myConcat("; ", "elephant", "giraffe", "lion", "cheetah"); - -// "sage. basil. oregano. pepper. parsley. " を返す -myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley"); -</pre> - <p>さらなる情報については、コア JavaScript リファレンスの <a href="/ja/Core_JavaScript_1.5_Reference/Objects/Function" title="ja/Core_JavaScript_1.5_Reference/Objects/Function">Function オブジェクト</a> をご覧ください。</p> - <p><strong>JavaScript 1.3 以前のバージョン</strong><br> - arguments オブジェクトは <code>Function</code> オブジェクトのプロパティであり、次のように関数の名前を前に付けることができます。</p> - functionName.arguments{{ mediawiki.external('i') }}</div> -<p>{{ PreviousNext("JavaScript/Guide/Calling_Functions", "JavaScript/Guide/Predefined_Functions") }}</p> diff --git a/files/ja/web/javascript/guide/variables/index.html b/files/ja/web/javascript/guide/variables/index.html deleted file mode 100644 index cebaecc949..0000000000 --- a/files/ja/web/javascript/guide/variables/index.html +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: 変数 -slug: Web/JavaScript/Guide/Variables ---- -<p>{{ 英語版章題("Variables") }}</p> -<h3 id=".E5.A4.89.E6.95.B0" name=".E5.A4.89.E6.95.B0">変数</h3> -<p>アプリケーションで値を識別する名前として変数を使用します。変数の名前はあるルールに従って付けなくてはなりません。変数の名前は<em>識別子</em>とも呼ばれます。</p> -<p>JavaScript の識別子は必ずアルファベットかアンダースコア (_) かドル記号 ($) から始まらなくてはなりません。続く文字は数字 (0-9) も使えます。JavaScript は大文字・小文字を区別するため、使えるアルファベットは "A" から "Z"(大文字)と "a" から "z"(小文字)です。</p> -<p>JavaScript 1.5 からは å や ü といった ISO 8859-1 や Unicode のアルファベットも識別子に使えます。<a href="/ja/Core_JavaScript_1.5_Guide/Unicode#Unicode_Escape_Sequences" title="ja/Core_JavaScript_1.5_Guide/Unicode#Unicode_Escape_Sequences">Unicode エスケープシーケンス</a> のページに列挙されている \uXXXX 形式の Unicode エスケープシーケンスも識別子に使用できます。</p> -<p><code>Number_hits</code> や <code>temp99</code> や <code>_name</code> が使用できる名前の例です。</p> -<p>{{ 英語版章題("Declaring Variables") }}</p> -<h4 id=".E5.A4.89.E6.95.B0.E3.81.AE.E5.AE.A3.E8.A8.80" name=".E5.A4.89.E6.95.B0.E3.81.AE.E5.AE.A3.E8.A8.80">変数の宣言</h4> -<p>2 つの方法で変数を宣言できます。</p> -<ul> - <li><a href="/ja/Core_JavaScript_1.5_Reference/Statements/var" title="ja/Core_JavaScript_1.5_Reference/Statements/var">var</a> というキーワードを使う。例えば、<code>var x = 42</code>。この構文は <a href="#.E5.A4.89.E6.95.B0.E3.81.AE.E3.82.B9.E3.82.B3.E3.83.BC.E3.83.97">ローカルおよびグローバル</a> 変数どちらの宣言にも使用可能です。</li> - <li>単に値を代入する。例えば、<code>x = 42</code>。これはいつでも <a href="#.E3.82.B0.E3.83.AD.E3.83.BC.E3.83.90.E3.83.AB.E5.A4.89.E6.95.B0">グローバル変数</a> を宣言できますが、{{ 原語併記("厳格な JavaScript 警告", "strict JavaScript warning") }}が発生します。この方法は使用すべきではありません。</li> -</ul> -<p>{{ 英語版章題("Evaluating Variables") }}</p> -<h4 id=".E5.A4.89.E6.95.B0.E3.81.AE.E8.A9.95.E4.BE.A1" name=".E5.A4.89.E6.95.B0.E3.81.AE.E8.A9.95.E4.BE.A1">変数の評価</h4> -<p><code>var</code> 文を使用し、初期化せずに宣言された変数は <a href="/ja/Core_JavaScript_1.5_Reference/Global_Properties/undefined" title="ja/Core_JavaScript_1.5_Reference/Global_Properties/undefined">undefined</a> の値をとります。</p> -<p>未宣言の変数にアクセスしようとすると、ReferenceError 例外が投げられます。</p> -<pre class="eval">var a; -print("a の値は " + a); // "a の値は undefined" を出力 -print("b の値は " + b); // ReferenceError 例外を投げる -</pre> -<p><code>undefined</code> を使うと変数に値が入っているかどうかを確かめられます。以下のコードでは、変数 <code>input</code> には値が代入されておらず、<code><a href="/ja/Core_JavaScript_1.5_Reference/Statements/if...else" title="ja/Core_JavaScript_1.5_Reference/Statements/if...else">if</a></code> 文での評価結果は <code>true</code> です。</p> -<pre class="eval">var input; -if(input === undefined){ - doThis(); -} else { - doThat(); -} -</pre> -<p><span class="comment">Not sure how the following is related to "Variables" section</span> <code>undefined</code> は真偽値コンテキストで使用されると <code>false</code> として振る舞います。例えば以下のコードでは、<code>myArray</code> の要素が未定義であるために関数 <code>myFunction</code> が実行されます。</p> -<pre class="eval">var myArray = new Array(); -if (!myArray[0]) myFunction(); -</pre> -<p>null 変数を評価すると、数値コンテキストにおいては null 値は 0 として振る舞います。また、真偽値コンテキストでは false として振る舞います。</p> -<pre class="eval">var n = null; -print(n * 32); // prints 0 -</pre> -<p>{{ 英語版章題("Variable Scope") }}</p> -<h4 id=".E5.A4.89.E6.95.B0.E3.81.AE.E3.82.B9.E3.82.B3.E3.83.BC.E3.83.97" name=".E5.A4.89.E6.95.B0.E3.81.AE.E3.82.B9.E3.82.B3.E3.83.BC.E3.83.97">変数のスコープ</h4> -<p>変数を関数の外側で宣言すると、その変数はその文書のどのコードからも使用できるようになるため、<em>グローバル</em>(大域)変数と呼ばれます。変数を関数の内部で宣言すると、その変数はその関数の中でしか使用できないため、<em>ローカル</em>(局所)変数と呼ばれます。</p> -<p>JavaScript には <a href="/ja/Core_JavaScript_1.5_Guide/Block_Statement#.E3.83.96.E3.83.AD.E3.83.83.E3.82.AF.E6.96.87" title="ja/Core_JavaScript_1.5_Guide/Block_Statement#.E3.83.96.E3.83.AD.E3.83.83.E3.82.AF.E6.96.87">ブロック文</a> のスコープがありません。むしろ、そのブロックを内包しているコードに対して局所化されます。例えば以下のコードは <code>condition</code> が <code>false</code> のとき、例外を投げずに 0 が出力されます。</p> -<pre class="eval">if (condition) { - var x = 5; -} -print(x ? x : 0); -</pre> -<p>JavaScript の変数に関する独特なこととして、後に宣言される変数を例外を発生させることなく参照できるというのも挙げられます。</p> -<pre class="eval">print(x === undefined); // "true" を出力 -var x = 3; -</pre> -<p>{{ 英語版章題("Global Variables") }}</p> -<h4 id=".E3.82.B0.E3.83.AD.E3.83.BC.E3.83.90.E3.83.AB.E5.A4.89.E6.95.B0" name=".E3.82.B0.E3.83.AD.E3.83.BC.E3.83.90.E3.83.AB.E5.A4.89.E6.95.B0">グローバル変数</h4> -<p><span class="comment">need links to pages discussing scope chains and the global object</span> グローバル変数は実際には<em>グローバルオブジェクト</em>のプロパティです。ウェブページではグローバルオブジェクトは <a href="/ja/DOM/window" title="ja/DOM/window">window</a> です。そのため、<code>window.<em>variable</em></code> という構文を使うことでグローバル変数をセットしたり、グローバル変数にアクセスしたりすることができます。</p> -<p>したがって、あるウィンドウやフレームで宣言したグローバル変数に、そのウィンドウやフレームの名前を指定すれば別のウィンドウやフレームからアクセスできます。例えば、<code>phoneNumber</code> という変数を <code>FRAMESET</code> 文書内で宣言すると、子フレームから <code>parent.phoneNumber</code> としてこの変数を参照することができます。</p> -<p>{{ 英語版章題("See Also") }}</p> -<h4 id=".E9.96.A2.E9.80.A3.E9.A0.85.E7.9B.AE" name=".E9.96.A2.E9.80.A3.E9.A0.85.E7.9B.AE">関連項目</h4> -<p><a href="/ja/Sharp_variables_in_JavaScript" title="ja/Sharp_variables_in_JavaScript">JavaScript のシャープ変数</a></p> -<p>{{ PreviousNext("JavaScript/Guide/Values", "JavaScript/Guide/Constants") }}</p> diff --git a/files/ja/web/javascript/guide/writing_a_regular_expression_pattern/index.html b/files/ja/web/javascript/guide/writing_a_regular_expression_pattern/index.html deleted file mode 100644 index 64da075317..0000000000 --- a/files/ja/web/javascript/guide/writing_a_regular_expression_pattern/index.html +++ /dev/null @@ -1,193 +0,0 @@ ---- -title: 正規表現パターンの記述 -slug: Web/JavaScript/Guide/Writing_a_Regular_Expression_Pattern ---- -<h3 id=".E6.AD.A3.E8.A6.8F.E8.A1.A8.E7.8F.BE.E3.83.91.E3.82.BF.E3.83.BC.E3.83.B3.E3.82.92.E6.9B.B8.E3.81.8F" name=".E6.AD.A3.E8.A6.8F.E8.A1.A8.E7.8F.BE.E3.83.91.E3.82.BF.E3.83.BC.E3.83.B3.E3.82.92.E6.9B.B8.E3.81.8F">正規表現パターンを書く</h3> - -<p>正規表現パターンは、<code>/abc/</code> のような単純な文字、または <code>/ab*c/</code> や <code>/Chapter (\d+)\.\d*/</code> のような単純な文字と特殊文字との組み合わせからなります。最後の例では記憶装置として使われている丸括弧が含まれています。パターンのこの部分でなされたマッチは後で使用できるように記憶されます。詳しくは <a href="/ja/docs/JavaScript/Guide/Working_with_Regular_Expressions/Using_Parenthesized_Substring_Matches" title="ja/docs/JavaScript/Guide/Working_with_Regular_Expressions/Using_Parenthesized_Substring_Matches">括弧で囲まれた部分文字列のマッチの使用</a> を参照してください。</p> - -<h4 id="単純なパターンの使用">単純なパターンの使用</h4> - -<p>単純なパターンは、直接マッチしている部分を見つけたい文字で構成されます。例えば、/abc/ というパターンは、実際に 'abc' という文字が一緒にその順で存在しているときにだけ、文字列中の文字の組み合わせにマッチします。"Hi, do you know your abc's?" や "The latest airplane designs evolved from slabcraft." といった文字列でのマッチは成功します。どちらの場合でも 'abc' という部分文字列にマッチします。"Grab crab" という文字列では 'abc' という部分文字列が含まれていないためマッチしません。</p> - -<h4 id="特殊文字の使用">特殊文字の使用</h4> - -<p>1 つ以上の b を見つけたり、ホワイトスペースを見つけたりといった直接マッチより高度なマッチの検索では、パターンに特殊文字を使用します。例えば <code>/ab*c/</code> というパターンでは 1 つの 'a' とその後ろに続く 0 個以上の 'b'(* は直前のアイテムの 0 回以上の出現を意味する)とそのすぐ後ろに続く 'c' からなる文字の組み合わせにマッチします。"cbbabbbbcdebc" という文字列ではこのパターンは 'abbbbc' という部分文字列にマッチします。</p> - -<p>以下の表で正規表現で使用できる特殊文字とその意味を詳しく説明します。</p> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th>文字</th> - <th>意味</th> - </tr> - <tr> - <td>\</td> - <td>次のうちのどちらか。 - <ul> - <li>通常は文字どおり扱われる文字に対して、次の文字は特殊であり、文字どおりに解釈すべきではないと指示する。例えば、<code>/b/ </code> は 'b' という文字にマッチする。b の前にバックスラッシュを置き、<code>/\b/</code> とすると、その文字は単語の区切りにマッチすることを意味する特殊文字になる。</li> - <li>通常は特殊文字として扱われる文字に対して、次の文字は特殊ではなく、文字どおりに解釈すべきであると指示する。例えば、* は直前のアイテムの 0 回以上の出現にマッチさせることを意味する特殊文字である。つまり、例えば <code>/a*/</code> は a の 0 文字以上の a へのマッチを意味する。* という文字そのものにマッチさせるには、その直前にバックスラッシュを置く。例えば、<code>/a\*/</code> は 'a*' にマッチする。</li> - </ul> - </td> - </tr> - <tr> - <td>^</td> - <td>入力の先頭にマッチする。複数行フラグが true にセットされている場合は、改行文字直後にもマッチする。 例えば、<code>/^A/</code> は "an A" の 'A' にはマッチしないが、"An A" の最初の 'A' にはマッチする。</td> - </tr> - <tr> - <td>$</td> - <td>入力の末尾にマッチする。複数行フラグが true にセットされている場合は、改行文字直前にもマッチする。 例えば、<code>/t$/</code> は "eater" の 't' にはマッチしないが、"eat" の 't' にはマッチする。</td> - </tr> - <tr> - <td>*</td> - <td>直前の文字の 0 回以上の繰り返しにマッチする。 例えば、<code>/bo*/</code> は "A ghost booooed" の 'boooo' や "A bird warbled" の 'b' にはマッチするが、"A goat grunted" ではマッチしない。</td> - </tr> - <tr> - <td>+</td> - <td>直前の文字の 1 回以上の繰り返しにマッチする。{1,} と同等。 例えば、<code>/a+/</code> は "candy" の 'a' や、"caaaaaaandy" のすべての a にマッチする。</td> - </tr> - <tr> - <td>?</td> - <td>直前の文字の 0 回か 1 回の繰り返しにマッチする。 - <p>例えば、<code>/e?le?/</code> は "angel" の 'el' や "angle" の 'le' にマッチする。</p> - - <p><span class="nowiki">*</span>、+、?、{} といった量指定子の直後に使用した場合、その量指定子をスキップ優先(最小回数にマッチ)にする。これはデフォルトとは逆であり、デフォルトは繰り返し優先(最大回数にマッチ)。例えば、/\d+/ は非グローバルで "123abc" の "123" にマッチするが、/\d+?/ の場合、"1" だけにマッチする。</p> - 先読み表現内でも使用できるが、これはこの表の x(?=y) および x(?!y) にて説明。</td> - </tr> - <tr> - <td>.</td> - <td>小数点は改行文字以外のどの 1 文字にもマッチする。 例えば、<code>/.n/</code> は "nay, an apple is on the tree" の 'an' や 'on' にはマッチするが、'nay' にはマッチしない。</td> - </tr> - <tr> - <td>(x)</td> - <td>'x' にマッチし、マッチしたものを記憶しておく。これはキャプチャする括弧と呼ぶ。 例えば、<code>/(foo)/</code> は "foo bar" の 'foo' にマッチし、これを記憶する。マッチした部分文字列は結果として生成される配列の要素 1, ..., b から参照できる。</td> - </tr> - <tr> - <td>(?:x)</td> - <td>'x' にマッチするが、マッチしたものは記憶しない。これはキャプチャしない括弧と呼ぶ。マッチした部分文字列は先程のような配列の要素 1, ..., n から参照することはできない。</td> - </tr> - <tr> - <td>x(?=y)</td> - <td>'x' に 'y' が続く場合のみ 'x' にマッチする。例えば、<code>/Jack(?=Sprat)/</code> は 'Jack' の後ろに 'Sprat' が続く場合のみ 'Jack' にマッチする。<code>/Jack(?=Sprat|Frost)/</code> は 'Jack' の後ろに 'Sprat' または 'Frost' が続く場合のみ 'Jack' にマッチする。しかしながら、'Sprat' も 'Frost' もマッチの結果には現れない。</td> - </tr> - <tr> - <td>x(?!y)</td> - <td>'x' に 'y' が続かない場合のみ 'x' にマッチする。例えば、<code>/\d+(?!\.)/</code> はある数に小数点が続かない場合のみその数にマッチする。正規表現 <code>/\d+(?!\.)/.exec("3.141")</code> は 141 にはマッチするが 3.141 にはマッチしない。</td> - </tr> - <tr> - <td>x|y</td> - <td>'x' または 'y' にマッチする。 例えば、<code>/green|red/</code> は "green apple" の "green' や "red apple" の 'red' にマッチする。</td> - </tr> - <tr> - <td>{n}</td> - <td>n には正の整数が入る。直前の文字がちょうど n 回出現するものにマッチする。 例えば、<code>/a{2}/</code> は "candy" の 'a' にはマッチしないが、"caandy" の すべての a にマッチする。また、"caaandy" の最初の 2 つの a にマッチする。</td> - </tr> - <tr> - <td>{n,}</td> - <td>n には正の整数が入る。直前の文字が少なくとも n 回出現するものにマッチする。 例えば、<code>/a{2,}/</code> は "candy" の 'a' にはマッチしないが、"caandy" や "caaaaaaandy" の すべての a にマッチする。</td> - </tr> - <tr> - <td>{n,m}</td> - <td>n および m には正の整数が入る。直前の文字が少なくとも n 回、多くとも m 回出現するものにマッチする。 例えば、<code>/a{1,3}/</code> は "cndy" ではマッチせず、"candy" の 'a'、"caandy" の最初の 2 つの a、"caaaaaaandy" の最初の 3 つの a にマッチする。"caaaaaaandy" では元の文字列に a が 4 つ以上あるが、マッチするのは "aaa" であることに注意。</td> - </tr> - <tr> - <td>[xyz]</td> - <td>文字の集合。囲まれた文字のどれにでもマッチする。ハイフンを用いて文字の範囲を指定することも可能。 例えば、<code>/[abcd]/</code> は <code>/[a-d]/</code> と同じ。これは "brisket" の 'b' や "city" の 'c' にマッチする。</td> - </tr> - <tr> - <td>[^xyz]</td> - <td>文字の集合の否定または補集合。角括弧で囲まれていないものにマッチする。ハイフンを用いて文字の範囲を指定することも可能。 例えば、<code>/[^abc]/</code> は <code>/[^a-c]/</code> と同じ。これは "brisket" の 'r' や "chop" の 'h' にマッチする。</td> - </tr> - <tr> - <td>[\b]</td> - <td>後退にマッチする。(\b と混同してはならない。)</td> - </tr> - <tr> - <td>\b</td> - <td>スペースや改行文字のような単語の区切りにマッチする。([\b] と混同してはならない。) 例えば、<code>/\bn\w/</code> は "noonday" の 'no' にマッチする。また、<code>/\wy\b/</code> は "possibly yesterday" の 'ly' にマッチする。</td> - </tr> - <tr> - <td>\B</td> - <td>単語の区切り以外の文字にマッチする。 例えば、<code>/\w\Bn/</code> は "noonday" の 'on' にマッチする。また、<code>/y\B\w/</code> は "possibly yesterday" の 'ye' にマッチする。</td> - </tr> - <tr> - <td>\cX</td> - <td>X には制御文字が入る。文字列中の制御文字にマッチする。 例えば、<code>/\cM/</code> は文字列中の control-M にマッチする。</td> - </tr> - <tr> - <td>\d</td> - <td>数字にマッチする。<code>[0-9]</code> と同等。 例えば、<code>/\d/</code> や <code>/[0-9]/</code> は "B2 is the suite number" の '2' にマッチする。</td> - </tr> - <tr> - <td>\D</td> - <td>数字以外の文字にマッチする。<code>[^0-9]</code> と同等。 例えば、<code>/\D/</code> や <code>/[^0-9]/</code> は "B2 is the suite number" の 'B' にマッチする。</td> - </tr> - <tr> - <td>\f</td> - <td>改ページにマッチする。</td> - </tr> - <tr> - <td>\n</td> - <td>改行にマッチする。</td> - </tr> - <tr> - <td>\r</td> - <td>復帰にマッチする。</td> - </tr> - <tr> - <td>\s</td> - <td>スペース、タブ、改ページ、改行を含む、1 つのホワイトスペース文字にマッチする。 <code>[ \f\n\r\t\v\u00A0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]</code> と同等。 例えば、<code>/\s\w*/</code> は "foo bar" の ' bar' にマッチする。</td> - </tr> - <tr> - <td>\S</td> - <td>ホワイトスペース以外の 1 文字にマッチする。<code>[^ \f\n\r\t\v\u00A0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]</code> と同等。 例えば、<code>/\S\w*/</code> は "foo bar" の 'foo' にマッチする。</td> - </tr> - <tr> - <td>\t</td> - <td>タブにマッチする。</td> - </tr> - <tr> - <td>\v</td> - <td>垂直タブにマッチする。</td> - </tr> - <tr> - <td>\w</td> - <td>アンダースコアを含むどの英数字にもマッチする。<code>[A-Za-z0-9_]</code> と同等。 例えば、<code>/\w/</code> は "apple" の 'a' や "$5.28" の '5' や "3D" の '3' にマッチする。</td> - </tr> - <tr> - <td>\W</td> - <td>前述以外の文字にマッチする。<code>[^A-Za-z0-9_]</code> と同等。 例えば、<code>/\W/</code> や <code>/[^$A-Za-z0-9_]/</code> は "50%" の '%' にマッチする。</td> - </tr> - <tr> - <td>\n</td> - <td>n には正の整数が入る。その正規表現の n 番目の括弧の部分にマッチする最後の部分文字列への後方参照(左括弧をカウントする)。 例えば、<code>/apple(,)\sorange\1/</code> は "apple, orange, cherry, peach" の 'apple, orange,' にマッチする。</td> - </tr> - <tr> - <td>\0</td> - <td>NUL 文字にマッチする。この後ろに他の数字を続けてはならない。</td> - </tr> - <tr> - <td>\xhh</td> - <td>hh(2 桁の 16 進数)というコードを持つ文字にマッチする。</td> - </tr> - <tr> - <td>\uhhhh</td> - <td>hhhh(4 桁の 16 進数)というコードを持つ文字にマッチする。</td> - </tr> - </tbody> -</table> - -<p><small><strong>表 4.1正規表現における特殊文字</strong></small></p> - -<h4 id="括弧の使用">括弧の使用</h4> - -<p>正規表現パターンの一部分を括弧で囲むことで、マッチした部分文字列のその部分を記憶しておくことができます。一度記憶すると、後からその部分文字列を呼び戻すことができます。これに関しては <a href="/ja/Core_JavaScript_1.5_Guide/Working_with_Regular_Expressions/Using_Parenthesized_Substring_Matches" title="ja/Core_JavaScript_1.5_Guide/Working_with_Regular_Expressions/Using_Parenthesized_Substring_Matches">括弧で囲まれた部分文字列のマッチの使用</a> で説明しています。</p> - -<p>例えば、<code>/Chapter (\d+)\.\d*/</code> というパターンでは、エスケープされた文字と特殊文字の部分がその例で、その部分を記憶するように指示しています。これは 'Chapter ' という文字列、それに続く 1 文字以上の数字(\d はいずれかの数字を意味し、+ は 1 回以上の繰り返しを意味する)、それに続く小数点(それ自体は特殊文字であり、小数点の前の \ はパターンが '.' という文字そのものを探すようにすることを意味する)、それに続く 0 文字以上の数字(\d は数字を意味し、* は 0 回以上の繰り返しを意味する)にマッチします。さらに、括弧を使うことで最初のマッチした数値を記憶させます。</p> - -<p>このパターンは "Open Chapter 4.3, paragraph 6" という文字列で見つかり、'4' が記憶されます。このパターンは "Chapter 3 and 4" では見つかりません。この文字列は '3' の後ろにピリオドがないためです。</p> - -<p>マッチした部分を記憶させることなく部分文字列にマッチさせたい場合は、その括弧においてパターンの前に <code>?:</code> を付けてください。例えば、<code>(?:\d+)</code> は 1 文字以上の数字にマッチしますが、マッチした文字は記憶されません。</p> - -<p>{{ PreviousNext("JavaScript/Guide/Creating_a_Regular_Expression", "JavaScript/Guide/Working_with_Regular_Expressions") }}</p> diff --git a/files/ja/web/javascript/introduction_to_object-oriented_javascript/index.html b/files/ja/web/javascript/introduction_to_object-oriented_javascript/index.html deleted file mode 100644 index cbe9e10a0a..0000000000 --- a/files/ja/web/javascript/introduction_to_object-oriented_javascript/index.html +++ /dev/null @@ -1,381 +0,0 @@ ---- -title: オブジェクト指向 JavaScript 入門 -slug: Web/JavaScript/Introduction_to_Object-Oriented_JavaScript -tags: - - Constructor - - Encapsulation - - Inheritance - - Intermediate - - JavaScript - - Members - - Namespace - - OOP - - Object - - Object-Oriented -translation_of: Learn/JavaScript/Objects -translation_of_original: Web/JavaScript/Introduction_to_Object-Oriented_JavaScript ---- -<div>{{jsSidebar("Introductory")}}</div> - -<p>オブジェクト指向を追求することで、JavaScript は強力かつ柔軟な{{Glossary("OOP", "オブジェクト指向プログラミング")}}能力を特色としています。この記事ではまずオブジェクト指向プログラミングの入門から始め、JavaScript のオブジェクトモデルの復習、そして最後に JavaScript のオブジェクト指向プログラミングの概念を説明します。</p> - -<h2 id="JavaScript_review" name="JavaScript_review">JavaScript の復習</h2> - -<p>変数、型、関数、スコープといった JavaScript の概念について自信がないのでしたら、<a href="/ja/docs/Web/JavaScript/A_re-introduction_to_JavaScript">JavaScript「再」入門</a>で該当するトピックをご覧いただくとよいでしょう。また、<a href="/ja/docs/Web/JavaScript/Guide">JavaScript ガイド</a>もご覧ください。</p> - -<h2 id="Object-oriented_programming" name="Object-oriented_programming">オブジェクト指向プログラミング</h2> - -<p>オブジェクト指向プログラミング (OOP) は、実世界を元にしたモデルの作成に{{glossary("abstraction", "抽象化")}}を使用する、プログラミングのパラダイムです。OOP は{{glossary("modularity", "モジュラリティ")}}、{{glossary("polymorphism", "ポリモーフィズム")}}、{{glossary("encapsulation", "カプセル化")}}といった、これまでに確立されたパラダイム由来の技術を複数使用しています。今日、人気がある多くのプログラミング言語 (Java、JavaScript、C#、C++、Python、PHP、Ruby、Objective-C など) が OOP をサポートしています。</p> - -<p>OOP はソフトウェアを関数の集まりや単なるコマンドのリスト(これまでの伝統的な見方)としてではなく、協調して動作するオブジェクトの集まりであると考えます。OOP では、各々のオブジェクトがメッセージを受信し、データを処理し、また他のオブジェクトへメッセージを送信できます。各々のオブジェクトは明確な役割や責任を持つ、独立した小さな機械であると見なせます。</p> - -<p>OOP はプログラミングにおける柔軟性や保守性の向上を促し、大規模ソフトウェアエンジニアリングにおいて広く普及しています。OOP はモジュラリティを強く重視しているため、オブジェクト指向によるコードは開発をシンプルにします。また、コードを後から理解することが容易になります。オブジェクト指向によるコードはモジュラリティが低いプログラミング方法よりも、直接的な分析、コーディング、複雑な状況や手続きの理解を促進します。<a href="#cite-1"><sup>1</sup></a></p> - -<h2 id="Terminology" name="Terminology">用語集</h2> - -<dl> - <dt>{{Glossary("Namespace", "ネームスペース")}} (名前空間)</dt> - <dd>開発者があらゆる機能をアプリケーション固有の一意な名前にまとめることができる一種の容器のことです。</dd> - <dt>{{Glossary("Class", "クラス")}}</dt> - <dd>オブジェクトの特性を定義するものです。クラスは、オブジェクトのプロパティやメソッドを定義するテンプレートです。</dd> - <dt>{{Glossary("Object", "オブジェクト")}}</dt> - <dd>クラスの実体です。</dd> - <dt>{{Glossary("Property", "プロパティ")}}</dt> - <dd>「色」などといったオブジェクトの特性です。</dd> - <dt>{{Glossary("Method", "メソッド")}}</dt> - <dd>「歩く」などといった、オブジェクトの能力です。これは、クラスに関連付けられたサブルーチンや関数です。</dd> - <dt>{{Glossary("Constructor", "コンストラクタ")}}</dt> - <dd>インスタンス化するときに呼び出されるメソッドです。コンストラクタの名前は通常、クラスの名前と同じです。</dd> - <dt>{{Glossary("Inheritance", "継承")}}</dt> - <dd>あるクラスが別のクラスから特性を引き継ぐことを指します。</dd> - <dt>{{Glossary("Encapsulation", "カプセル化")}}</dt> - <dd>データと、そのデータを使用するメソッドとをまとめる手法のことです。</dd> - <dt>{{Glossary("Abstraction", "抽象化")}}</dt> - <dd>実世界のモデルが、オブジェクトの複雑な継承、メソッド、プロパティの集合体によって適切に再現されている状態を指します。</dd> - <dt>{{Glossary("Polymorphism", "ポリモーフィズム")}}</dt> - <dd>Poly は "<em>many</em>"、morphism は "<em>forms</em>" を意味します。別々のクラスが同じメソッドやプロパティを定義可能であることを表します。</dd> -</dl> - -<p>オブジェクト指向プログラミングのより広範な説明については、Wikipedia の {{interwiki("wikipedia", "オブジェクト指向プログラミング")}} をご覧ください。</p> - -<h2 id="Prototype-based_programming" name="Prototype-based_programming">プロトタイプベースプログラミング</h2> - -<p>プロトタイプベースのプログラミングはクラスを使用せず、既存の<strong>プロトタイプ</strong>オブジェクトをデコレート(あるいは拡張)してそのオブジェクトの持つ挙動を再利用する(クラスベースの言語における継承と同等)ことで実現される OOP モデルです(クラスレス、プロトタイプ指向、あるいはインスタンスベースプログラミングとも呼ばれます)。</p> - -<p>プロトタイプベース言語として先駆けの(そしてもっとも正統な)代表例は、David Ungar 氏と Randall Smith 氏によって開発された {{interwiki("wikipedia", "Self")}} です。とはいえ、クラスレスのプログラミングスタイルは最近ますます人気が高まり、JavaScript、Cecil、NewtonScript、Io、MOO、REBOL、Kevo、Squeak (ソフトウェア Morphic のコンポーネント操作の際の Viewer フレームワークとして使われています)などのプログラミング言語に採用されました。</p> - -<h2 id="JavaScript_object_oriented_programming" name="JavaScript_object_oriented_programming">JavaScript のオブジェクト指向プログラミング</h2> - -<h3 id="Namespace" name="Namespace">ネームスペース</h3> - -<p>ネームスペース(名前空間)とは、開発者が一意なアプリケーション固有の名前を付けて、機能をまとめることができる一種の容器です。<strong>JavaScript では、ネームスペースはメソッド、プロパティ、オブジェクトを包含する別のオブジェクトとなります。</strong></p> - -<p>{{note('JavaScript では通常のオブジェクトとネームスペースとの間に、言語レベルの違いがない点に留意することが重要です。これは他の多くのオブジェクト指向言語とは異なっており、新たな JavaScript プログラマを混乱させることがあります。')}}</p> - -<p>JavaScript でネームスペースを作成する考え方はシンプルです。グローバルオブジェクトをひとつ作成して、すべての変数、メソッド、関数をそのオブジェクトのプロパティとすればよいのです。ネームスペースを使用すると、アプリケーション内で名前が衝突する可能性が低下します。これは各アプリケーションのオブジェクトが、アプリケーションで定義したグローバルオブジェクトのプロパティとなるからです。</p> - -<p>MYAPP という名前のグローバルオブジェクトを作成しましょう :</p> - -<pre class="brush: js">// グローバルネームスペース -var MYAPP = MYAPP || {};</pre> - -<p>上記のサンプルコードでは、始めに MYAPP が(同じファイルまたは別のファイルで)すでに定義されているかを確認します。定義されている場合は、既存の MYAPP グローバルオブジェクトを使用します。定義されていない場合はメソッド、関数、変数、オブジェクトをカプセル化する、MYAPP という名前の空のオブジェクトを作成します。</p> - -<p>サブネームスペースも作成できます(グローバルオブジェクトを最初に定義する必要があることに注意):</p> - -<pre class="brush: js">// サブネームスペース -MYAPP.event = {};</pre> - -<p>ネームスペースを作成して変数、関数、メソッドを追加する構文は以下のようになります :</p> - -<pre class="brush: js">// 共通のメソッドやプロパティ向けに MYAPP.commonMethod という名前のコンテナを作成 -MYAPP.commonMethod = { - regExForName: "", // 名前を検証するための正規表現を定義 - regExForPhone: "", // 電話番号を検証するための正規表現を定義 - validateName: function(name){ - // 名前に対してなんらかの処理を行う。"this.regExForName" を使用して - // 変数 regExForName にアクセス可能 - }, - - validatePhoneNo: function(phoneNo){ - // 電話番号に対してなんらかの処理を行う - } -} - -// オブジェクトとともにメソッドを定義する -MYAPP.event = { - addListener: function(el, type, fn) { - // 処理 - }, - removeListener: function(el, type, fn) { - // 処理 - }, - getEvent: function(e) { - // 処理 - } - - // 他のメソッドやプロパティを追加できる -} - -// addListener メソッドを使用する構文: -MYAPP.event.addListener("yourel", "type", callback);</pre> - -<h3 id="Standard_built-in_objects" name="Standard_built-in_objects">標準ビルトインオブジェクト</h3> - -<p>JavaScript は、例えば <code>Math</code>、<code>Object</code>、<code>Array</code>、<code>String</code> といったコアに組み込まれたオブジェクトがあります。以下の例では、乱数を取得するために <code>Math</code> オブジェクトの <code>random()</code> メソッドを使用する方法を示したものです。</p> - -<pre class="brush: js">console.log(Math.random()); -</pre> - -<div class="note"><strong>註:</strong> この例、および以降の例では、{{domxref("console.log()")}} という名前の関数がグローバルで定義されていると仮定しています。実際は、<code>console.log()</code> 関数は JavaScript そのものの一部ではありませんが、多くのブラウザがデバッグ用に実装しています。</div> - -<p>JavaScript におけるコアオブジェクトの一覧については、<a href="/ja/docs/Web/JavaScript/Reference/Global_Objects">JavaScript リファレンスの標準ビルトインオブジェクト</a>をご覧ください。</p> - -<p>JavaScript ではすべてのオブジェクトが <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Object"><code>Object</code></a> オブジェクトのインスタンスであり、それゆえに Object の全プロパティおよび全メソッドを継承します。</p> - -<h3 id="Custom_objects" name="Custom_objects">カスタムオブジェクト</h3> - -<h4 id="The_class" name="The_class">クラス</h4> - -<p>JavaScript はプロトタイプベースの言語であり、C++ や Java でみられる <code>class</code> 文がありません。これは時に、<code>class</code> 文を持つ言語に慣れているプログラマを混乱させます。その代わりに、JavaScript ではクラスのコンストラクタとして関数を使用します。クラスの定義は、関数の定義と同じほど簡単です。以下の例では、空のコンストラクタを使って Person という名前の新たなクラスを定義しています。</p> - -<pre class="brush: js">var Person = function () {}; -</pre> - -<h4 id="The_object_(class_instance)" name="The_object_(class_instance)">オブジェクト(クラスのインスタンス)</h4> - -<p><code>obj</code> オブジェクトの新たなインスタンスを生成するには <code>new obj</code> 文を使用し、その結果(<code>obj</code> 型を持つ)を、後からアクセスするための変数に代入します。</p> - -<p>前出の例で、<code>Person</code> という名前のクラスを定義しました。以下の例では、2 つのインスタンス(<code>person1</code> と <code>person2</code>)を生成しています。</p> - -<pre class="brush: js">var person1 = new Person(); -var person2 = new Person(); -</pre> - -<div class="note"><strong>註:</strong> 初期化されていないインスタンスを生成する、新たに追加されたインスタンス化方法については、 {{jsxref("Object.create()")}} をご覧ください。</div> - -<h4 id="The_constructor" name="The_constructor">コンストラクタ</h4> - -<p>コンストラクタは、インスタンス化の際(オブジェクトのインスタンスが生成されたとき)に呼び出されます。コンストラクタは、クラスのメソッドです。JavaScript では、関数がオブジェクトのコンストラクタとして働きます。したがって、コンストラクタメソッドを明示的に定義する必要はありません。クラス内で定義されたすべてのアクションが、インスタンス化の際に実行されます。</p> - -<p>コンストラクタはオブジェクトのプロパティの設定や、オブジェクトの使用準備を行うメソッドの呼び出しを行うために使用されます。クラスのメソッドの追加やメソッドの定義は別の構文を使用して行うことについては、後ほど説明します。</p> - -<p>以下の例では <code>Person</code> をインスタンス化する際に、コンストラクタがメッセージをログに出力します。</p> - -<pre class="brush: js">var Person = function () { - console.log('instance created'); -}; - -var person1 = new Person(); -var person2 = new Person(); -</pre> - -<h4 id="The_property_(object_attribute)" name="The_property_(object_attribute)">プロパティ(オブジェクトの属性)</h4> - -<p>プロパティは、クラス内にある変数です。オブジェクトのインスタンスはすべて、それらのプロパティを持ちます。プロパティがそれぞれのインスタンスで作成されるように、プロパティはコンストラクタ(関数)内で設定されます。</p> - -<p>カレントオブジェクトを示す <code>this</code> キーワードを使用して、クラス内でプロパティを扱うことができます。クラス外からプロパティにアクセス(読み取りや書き込み)するには、<code>InstanceName.Property</code> という構文を使用します。これは C++、Java、その他の言語と同じ構文です(クラスの内部では、プロパティの値の取得や設定に <code>this.Property</code> 構文を使用します)。</p> - -<p>以下の例では、<code>Person</code> クラスをインスタンス化する際に <code>firstName</code> プロパティを定義しています:</p> - -<pre class="brush: js">var Person = function (firstName) { - this.firstName = firstName; - console.log('Person instantiated'); -}; - -var person1 = new Person('Alice'); -var person2 = new Person('Bob'); - -// オブジェクトの firstName プロパティを表示する -console.log('person1 is ' + person1.firstName); // "person1 is Alice" と出力 -console.log('person2 is ' + person2.firstName); // "person2 is Bob" と出力 -</pre> - -<h4 id="The_methods" name="The_methods">メソッド</h4> - -<p>メソッドは関数です(また、関数と同じように定義されます)が、他はプロパティと同じ考え方に従います。メソッドの呼び出しはプロパティへのアクセスと似ていますが、メソッド名の終わりに <code>()</code> を付加して、引数を伴うことがあります。メソッドを定義するには、クラスの <code>prototype</code> プロパティの名前付きプロパティに、関数を代入します。関数を代入した名前を使用して、オブジェクトのメソッドを呼び出すことができます。</p> - -<p>以下の例では、<code>Person</code> クラスで <code>sayHello()</code> メソッドを定義および使用しています。</p> - -<pre class="brush: js">var Person = function (firstName) { - this.firstName = firstName; -}; - -Person.prototype.sayHello = function() { - console.log("Hello, I'm " + this.firstName); -}; - -var person1 = new Person("Alice"); -var person2 = new Person("Bob"); - -// Person の sayHello メソッドを呼び出す -person1.sayHello(); // "Hello, I'm Alice" と出力 -person2.sayHello(); // "Hello, I'm Bob" と出力 -</pre> - -<p>JavaScript のメソッドはオブジェクトにプロパティとして割り付けられた通常の関数であり、「状況に関係なく」呼び出せます。以下のサンプルコードについて考えてみましょう:</p> - -<pre class="brush: js">var Person = function (firstName) { - this.firstName = firstName; -}; - -Person.prototype.sayHello = function() { - console.log("Hello, I'm " + this.firstName); -}; - -var person1 = new Person("Alice"); -var person2 = new Person("Bob"); -var helloFunction = person1.sayHello; - -// "Hello, I'm Alice" と出力 -person1.sayHello(); - -// "Hello, I'm Bob" と出力 -person2.sayHello(); - -// "Hello, I'm undefined" と出力 -// (strict モードでは TypeError で失敗する) -helloFunction(); - -// true と出力 -console.log(helloFunction === person1.sayHello); - -// true と出力 -console.log(helloFunction === Person.prototype.sayHello); - -// "Hello, I'm Alice" と出力 -helloFunction.call(person1);</pre> - -<p>この例で示すように、<code>sayHello</code> 関数を参照しているもの(<code>person1</code>、<code>Person.prototype</code>、<code>helloFunction</code> 変数など)すべてが、<strong>同一の関数</strong>を示しています。関数を呼び出しているときの <code>this</code> の値は、関数の呼び出し方に依存します。もっとも一般的な、オブジェクトのプロパティから関数にアクセスする形式 (<code>person1.sayHello()</code>) で <code>this</code> を呼び出すときは、その関数を持つオブジェクト (<code>person1</code>) を <code>this</code> に設定します。これが、<code>person1.sayHello()</code> で名前として "Alice"、<code>person2.sayHello()</code> で名前として "Bob" が使用される理由です。一方、他の方法で呼び出す場合は <code>this</code> に設定されるものが変わります。変数 (<code>helloFunction()</code>) から <code>this</code> を呼び出すと、グローバルオブジェクト(ブラウザでは <code>window</code>)を <code>this</code> に設定します。このオブジェクトは(おそらく)<code>firstName</code> プロパティを持っていないため、"Hello, I'm undefined" になります(これは loose モードの場合です。<a href="/ja/docs/Web/JavaScript/Reference/Strict_mode" title="Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode">strict モード</a>では異なる結果(エラー)になりますが、ここでは混乱を避けるために詳細は割愛します)。あるいは、例の最後で示したように <code>Function#call</code> (または <code>Function#apply</code>)を使用して、<code>this</code> を明示的に設定できます。</p> - -<div class="note"><strong>註:</strong> <code>this</code> について、詳しくは {{jsxref("Global_Objects/Function/call","Function#call")}} および {{jsxref("Global_Objects/Function/apply","Function#apply")}} をご覧ください。</div> - -<h4 id="Inheritance" name="Inheritance">継承</h4> - -<p>継承は、1 つ以上のクラスを特化したバージョンとしてクラスを作成する方法です(<strong>JavaScript は単一継承のみサポートしています</strong>)。特化したクラスは一般的に<strong>子</strong>と呼ばれ、またそれ以外のクラスは一般的に<strong>親</strong>と呼ばれます。JavaScript では親クラスのインスタンスを子クラスに代入して、特化させることにより継承を行います。現代のブラウザでは、継承の実装に {{jsxref("Global_Objects/Object/create","Object.create","#Classical_inheritance_with_Object.create()")}} を使用することもできます。</p> - -<div class="note"> -<p><strong>註:</strong> JavaScript は子クラスの <code>prototype.constructor</code>({{jsxref("Global_Objects/Object/prototype","Object.prototype")}} をご覧ください)を検出しないため、手動で明示しなければなりません。Stackoverflow に投稿された質問 "<a href="http://stackoverflow.com/questions/8453887/why-is-it-necessary-to-set-the-prototype-constructor">Why is it necessary to set the prototype constructor?</a>" をご覧ください。</p> -</div> - -<p>以下の例では、<code>Person</code> の子クラスとして <code>Student</code> クラスを定義しています。そして、<code>sayHello()</code> メソッドの再定義と <code>sayGoodBye()</code> メソッドの追加を行っています。</p> - -<pre class="brush: js">// Person コンストラクタを定義する -var Person = function(firstName) { - this.firstName = firstName; -}; - -// Person.prototype にメソッドを 2 つ追加する -Person.prototype.walk = function(){ - console.log("I am walking!"); -}; - -Person.prototype.sayHello = function(){ - console.log("Hello, I'm " + this.firstName); -}; - -// Student コンストラクタを定義する -function Student(firstName, subject) { - // 親のコンストラクタを呼び出す。呼び出しの際に "this" が - // 適切に設定されるようにする (Function#call を使用) - Person.call(this, firstName); - - // Student 固有のプロパティを初期化する - this.subject = subject; -}; - -// Person.prototype を継承する、Student.prototype オブジェクトを作成する -// 註: ここでよくある間違いが、Student.prototype を生成するために -// "new Person()" を使用することです。これは様々な理由で間違っていますが、 -// まずこれでは Person の "firstName" 引数に渡すものがありません。 -// Person を呼び出す正しい場所はこれより前の、 -// Student から呼び出します。 -Student.prototype = Object.create(Person.prototype); // 以下の注釈を参照 - -// "constructor" プロパティが Student を指すように設定する -Student.prototype.constructor = Student; - -// "sayHello" メソッドを置き換える -Student.prototype.sayHello = function(){ - console.log("Hello, I'm " + this.firstName + ". I'm studying " - + this.subject + "."); -}; - -// "sayGoodBye" メソッドを追加する -Student.prototype.sayGoodBye = function(){ - console.log("Goodbye!"); -}; - -// 使用例: -var student1 = new Student("Janet", "Applied Physics"); -student1.sayHello(); // "Hello, I'm Janet. I'm studying Applied Physics." -student1.walk(); // "I am walking!" -student1.sayGoodBye(); // "Goodbye!" - -// instanceof が正常に機能するかをチェック -console.log(student1 instanceof Person); // true -console.log(student1 instanceof Student); // true -</pre> - -<p><code>Student.prototype = Object.create(Person.prototype);</code> という行について :<br> - {{jsxref("Global_Objects/Object/create","Object.create")}} が存在しない古い JavaScript エンジンでは、「{{原語併記("ポリフィル","polyfill")}}」 ("shim" とも呼ばれます。リンク先の記事をご覧ください)または同様の結果になる以下のような関数を使用できます。:</p> - -<pre class="brush: js">function createObject(proto) { - function ctor() { } - ctor.prototype = proto; - return new ctor(); -} - -// 使用法: -Student.prototype = createObject(Person.prototype); -</pre> - -<div class="note"><strong>註:</strong> Object.create や古いエンジン向けの shim が何を行っているかについては、{{jsxref("Global_Objects/Object/create","Object.create")}} をご覧ください。</div> - -<p>オブジェクトをインスタンス化する方法を問わずに、<code>this</code> の参照先を適切に指定するのは時に難しいものです。ですが、これを容易にするシンプルなイディオムがあります。</p> - -<pre class="brush: js">var Person = function(firstName) { - if (this instanceof Person) { - this.firstName = firstName; - } else { - return new Person(firstName); - } -} -</pre> - -<h4 id="Encapsulation" name="Encapsulation">カプセル化</h4> - -<p>前の例では、<code>Person</code> クラスによる <code>walk()</code> メソッドの実装状況を <code>Student</code> が知らなくても、そのメソッドを使用できました。<code>Student</code> クラスは変更の必要がない限り、そのメソッドを明示的に定義する必要はありません。すべてのクラスのデータとメソッドがひとつのユニットに収められていることから、これを<strong>カプセル化</strong>と呼びます。</p> - -<p>情報を隠蔽することは、他の言語でも <code>private</code> または <code>protected</code> なメソッドやプロパティという形で一般的な機能です。JavaScript でも同様のことをシミュレートできますが、オブジェクト指向プログラミングに必須というわけではありません。<a href="#cite-2"><sup>2</sup></a></p> - -<h4 id="Abstraction" name="Abstraction">抽象化</h4> - -<p>抽象化は、取り組んでいる問題の箇所を継承(特殊化)や合成によってモデル化することを可能にする仕組みです。JavaScript では継承によって特殊化を、クラスのインスタンスを別のオブジェクトの属性値にすることで合成を実現しています。</p> - -<p>JavaScript の <code>Function</code> クラスは <code>Object</code> クラスから継承しています(これはモデルを特殊化している一例です)。また、<code>Function.prototype</code> プロパティは <code>Object</code> のインスタンスです (これは合成の一例です)。</p> - -<pre class="brush: js">var foo = function () {}; - -// "foo is a Function: true" と出力 -console.log('foo is a Function: ' + (foo instanceof Function)); - -// "foo.prototype is an Object: true" と出力 -console.log('foo.prototype is an Object: ' + (foo.prototype instanceof Object));</pre> - -<h4 id="Polymorphism" name="Polymorphism">ポリモーフィズム</h4> - -<p>すべてのメソッドやプロパティが <code>prototype</code> プロパティの内部で実装されているのと同じように、異なるクラスで同じ名前のメソッドを定義できます。メソッドは 2 つのクラスに親子関係(すなわち、あるクラスが別のクラスから継承されている)がない限り、自身が定義されたクラスに収められます。</p> - -<h2 id="Notes" name="Notes">注記</h2> - -<p>これらは JavaScript でオブジェクト指向プログラミングを実装する唯一の方法ではありません。この点で JavaScript はとても融通がききます。同様に、ここで示した技術は言語ハックをまったくしていませんし、他言語のオブジェクト理論における実装を模倣してもいません。</p> - -<p>このほかにも、JavaScript によるより高度なオブジェクト指向プログラミングのテクニックがありますが、この入門記事で扱う範囲を超えます。</p> - -<h2 id="References" name="References">参考情報</h2> - -<ol> - <li>Wikipedia: "<a href="http://en.wikipedia.org/wiki/Object-oriented_programming" name="cite-1">Object-oriented programming</a>" (<a href="http://ja.wikipedia.org/wiki/%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E6%8C%87%E5%90%91%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0">日本語版</a>)</li> - <li>Wikipedia: "<a href="http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29" name="cite-2">Encapsulation (object-oriented programming)</a>" (<a href="http://ja.wikipedia.org/wiki/%E3%82%AB%E3%83%97%E3%82%BB%E3%83%AB%E5%8C%96">日本語版</a>)</li> -</ol> diff --git a/files/ja/web/javascript/introduction_to_using_xpath_in_javascript/index.html b/files/ja/web/javascript/introduction_to_using_xpath_in_javascript/index.html deleted file mode 100644 index 8d63ce70da..0000000000 --- a/files/ja/web/javascript/introduction_to_using_xpath_in_javascript/index.html +++ /dev/null @@ -1,411 +0,0 @@ ---- -title: JavaScript で XPath を使用する -slug: Web/JavaScript/Introduction_to_using_XPath_in_JavaScript -translation_of: Web/XPath/Introduction_to_using_XPath_in_JavaScript ---- -<p>このドキュメントでは、JavaScript の内部、拡張機能、そして Web サイトから <a href="/ja/docs/Web/XPath">XPath</a> を使用するためのインターフェイスについて説明します。Mozilla は <a class="external" href="https://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/">DOM 3 XPath</a> をかなりの量実装しており、XPath 式は HTML と XML ドキュメントの両方に対して実行できます。</p> - -<p>XPath を使用するための主なインターフェースは、<a href="/ja/docs/Web/API/Document">Document</a> オブジェクトの <a href="/ja/docs/Web/API/Document/evaluate">evaluate</a> 関数です。</p> - -<h2 id="document.evaluate" name="document.evaluate">document.evaluate</h2> - -<p>このメソッドは、<a href="/ja/docs/Glossary/XML">XML</a> ベースのドキュメント (HTML ドキュメントを含む) に対して <a href="/ja/docs/Web/XPath">XPath</a> 式を評価し、<code><a href="/ja/docs/Web/API/XPathResult">XPathResult</a></code> オブジェクトを返します。このメソッドの既存のドキュメントは <a href="/ja/docs/Web/API/Document/evaluate">document.evaluate</a> にありますが、今のところ我々が必要としているものには乏しいです。</p> - -<pre class="brush: js notranslate">var xpathResult = document.evaluate( xpathExpression, contextNode, namespaceResolver, resultType, result ); -</pre> - -<h3 id="Parameters" name="Parameters">Parameters</h3> - -<p><a href="/ja/docs/Web/API/Document/evaluate">evaluate</a> 関数は合計5つのパラメータを取ります。</p> - -<ul> - <li><code>xpathExpression</code>: 評価される XPath 式を含む文字列</li> - <li><code>contextNode</code>: <code>xpathExpression</code> が評価されるべきドキュメント内のノード。<a href="/ja/docs/Web/API/Document">Document</a> ノードが最も一般的に使用されます</li> - <li><code>namespaceResolver</code>: <code>xpathExpression</code> 内に含まれる名前空間接頭辞を渡す関数で、その接頭辞に関連付けられた名前空間 URI を表す文字列を返します。これにより、XPath 式で使用されている接頭辞とドキュメント内で使用されている可能性のある異なる接頭辞との変換が可能になります。この関数は、以下のいずれかの方法で利用できます - <ul> - <li><code><a href="/ja/docs/Using_XPath#Node-specific_evaluator_function" title="en/XPathEvaluator">XPathEvaluator</a></code> オブジェクトの <code><a href="/ja/docs/Web/API/Document/createNSResolver">createNSResolver</a></code> メソッドを使用して<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#Implementing_a_Default_Namespace_Resolver">作成します</a>。事実上、これを使用する必要があります</li> - <li><code>null</code>です。これは、HTML ドキュメントや名前空間プレフィックスが使用されていない場合に使用することができます。<code>xpathExpression</code>に 名前空間プレフィックスが含まれている場合、<code>NAMESPACE_ERR</code> というコードで <code>DOMException</code> がスローされることに注意してください</li> - <li>カスタムのユーザ定義関数。詳細は、付録の <a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#Implementing_a_User_Defined_Namespace_Resolver">ユーザー定義名前空間リゾルバの使用法</a> を参照してください</li> - </ul> - </li> - <li><code>resultType</code>: 評価の結果として返される結果の型を指定する<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#XPathResult_Defined_Constants">定数</a>です。最も一般的に渡される定数は <code>XPathResult.ANY_TYPE</code> で、これは XPath 式の結果を最も自然な型として返します。付録には、<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#XPathResult_Defined_Constants">利用可能な定数</a>の完全なリストを含むセクションがあります。これらの定数は以下の「<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#Specifying_the_Return_Type">戻り値の型の指定</a>」のセクションで説明されています</li> - <li><code>result</code>: 既存の <code>XPathResult</code> オブジェクトを指定すると、そのオブジェクトが再利用されて結果が返されます。<code>null</code> を指定すると、新しい <code>XPathResult</code> オブジェクトが作成されます</li> -</ul> - -<h3 id="Return_Value" name="Return_Value">Return Value</h3> - -<p><code>resultType</code> パラメータで<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#Specifying_the_Return_Type">指定された</a>型の <code>XPathResult</code> オブジェクトを返します。<code>XPathResult</code> インターフェースは<a href="/ja/docs/Web/API/XPathResult">ここ</a>で定義されています。</p> - -<h3 id="Implementing_a_Default_Namespace_Resolver" name="Implementing_a_Default_Namespace_Resolver">Implementing a Default Namespace Resolver</h3> - -<p><a href="/ja/docs/Web/API/document" title="en/DOM/document">document</a> オブジェクトの <code>createNSResolver</code> メソッドを使用して名前空間リゾルバを作成します。</p> - -<pre class="brush: js notranslate">var nsResolver = document.createNSResolver( contextNode.ownerDocument == null ? contextNode.documentElement : contextNode.ownerDocument.documentElement ); -</pre> - -<p><span class="comment">Or alternatively by using the <code>createNSResolver</code> method of a <code>XPathEvaluator</code> object. <pre> var xpEvaluator = new XPathEvaluator(); var nsResolver = xpEvaluator.createNSResolver( contextNode.ownerDocument == null ? contextNode.documentElement : contextNode.ownerDocument.documentElement ); </pre></span> そして、<code>namespaceResolver</code> パラメータとして <code>nsResolver</code> 変数である <code>document.evaluate</code> を渡します。</p> - -<p>注意: XPath は、ヌル名前空間の要素にのみマッチするように、接頭辞のない QNames を定義しています。XPath では、通常の要素参照 (例: <code><span class="nowiki">xmlns='http://www.w3.org/1999/xhtml</span>'</code> の <code>p[@id='_myid']</code>) に適用されるデフォルトの名前空間を拾う方法はありません。NULL ではない名前空間のデフォルト要素にマッチさせるには、<code>['namespace-uri()='<span class="nowiki">http://www.w3.org/1999/xhtml</span>' and name()='p' and @id='_myid']</code> のような形式を使用して特定の要素を参照する必要があります (<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#Using_XPath_functions_to_reference_elements_with_a_default_namespace">このアプローチ</a>は、名前空間がわからない動的な XPath の場合にうまく機能します)。後者の方法を取りたい場合は、<a href="/ja/docs/Web/JavaScript/Introduction_to_using_XPath_in_JavaScript#Implementing_a_User_Defined_Namespace_Resolver">ユーザ定義の名前空間リゾルバを作成する方法</a>を参照してください。</p> - -<h3 id="Notes" name="Notes">Notes</h3> - -<p>任意の DOM ノードを名前空間を解決するように適応させ、 <a href="/ja/docs/Web/XPath">XPath</a> 式をドキュメント内で出現したノードのコンテキストからの相対評価を簡単に行えるようにします。このアダプタは、ノード上の DOM Level 3 メソッド <code>lookupNamespaceURI</code> と同様に動作し、 <code>lookupNamespaceURI</code> が呼び出された時点でのノードの階層内で利用可能な現在の情報を使用して、指定したプレフィックスから <code>namespaceURI</code> を解決します。また、暗黙の <code>xml</code> 接頭辞も正しく解決します。</p> - -<h3 id="Specifying_the_Return_Type" name="Specifying_the_Return_Type">Specifying the Return Type</h3> - -<p>The returned variable <code>xpathResult</code> from <code>document.evaluate</code> can either be composed of individual nodes (<a href="#Simple_Types">simple types</a>), or a collection of nodes (<a href="#Node-Set_Types">node-set types</a>).</p> - -<h4 id="Simple_Types" name="Simple_Types">Simple Types</h4> - -<p><code>resultType</code> に希望する結果タイプがどちらかに指定されている場合。</p> - -<ul> - <li><code>NUMBER_TYPE</code> - a double</li> - <li><code>STRING_TYPE</code> - 文字列</li> - <li><code>BOOLEAN_TYPE</code> - 真偽値</li> -</ul> - -<p><code>XPathResult</code> オブジェクトの以下のプロパティにそれぞれアクセスして、式の戻り値を取得します。</p> - -<ul> - <li><code>numberValue</code></li> - <li><code>stringValue</code></li> - <li><code>booleanValue</code></li> -</ul> - -<h5 id="Example" name="Example">Example</h5> - -<p>The following uses the XPath expression <code><a href="/en-US/docs/XPath/Functions/count" title="en/XPath/Functions/count">count(//p)</a></code> to obtain the number of <code><p></code> elements in an HTML document:</p> - -<pre class="brush: js notranslate">var paragraphCount = document.evaluate( 'count(//p)', document, null, XPathResult.ANY_TYPE, null ); - -alert( 'This document contains ' + paragraphCount.numberValue + ' paragraph elements' ); -</pre> - -<p>Although JavaScript allows us to convert the number to a string for display, the XPath interface will not automatically convert the numerical result if the <code>stringValue</code> property is requested, so the following code will <strong>not</strong> work:</p> - -<pre class="brush: js notranslate">var paragraphCount = document.evaluate('count(//p)', document, null, XPathResult.ANY_TYPE, null ); - -alert( 'This document contains ' + paragraphCount.stringValue + ' paragraph elements' ); -</pre> - -<p>Instead, it will return an exception with the code <code>NS_DOM_TYPE_ERROR</code>.</p> - -<h4 id="Node-Set_Types" name="Node-Set_Types">Node-Set Types</h4> - -<p>The <code>XPathResult</code> object allows node-sets to be returned in 3 principal different types:</p> - -<ul> - <li><a href="#Iterators">Iterators</a></li> - <li><a href="#Snapshots">Snapshots</a></li> - <li><a href="#First_Node">First Nodes</a></li> -</ul> - -<h5 id="Iterators" name="Iterators">Iterators</h5> - -<p>When the specified result type in the <code>resultType</code> parameter is either:</p> - -<ul> - <li><code>UNORDERED_NODE_ITERATOR_TYPE</code></li> - <li><code>ORDERED_NODE_ITERATOR_TYPE</code></li> -</ul> - -<p>The <code>XPathResult</code> object returned is a node-set of matched nodes which will behave as an iterator, allowing us to access the individual nodes contained by using the <code>iterateNext()</code> method of the <code>XPathResult</code>.</p> - -<p>Once we have iterated over all of the individual matched nodes, <code>iterateNext()</code> will return <code>null</code>.</p> - -<p>Note however, that if the document is mutated (the document tree is modified) between iterations that will invalidate the iteration and the <code>invalidIteratorState</code> property of <code>XPathResult</code> is set to <code>true</code>, and a <code>NS_ERROR_DOM_INVALID_STATE_ERR</code> exception is thrown.</p> - -<h6 id="Iterator_Example" name="Iterator_Example">Iterator Example</h6> - -<pre class="brush: js notranslate">var iterator = document.evaluate('//phoneNumber', documentNode, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null ); - -try { - var thisNode = iterator.iterateNext(); - - while (thisNode) { - alert( thisNode.textContent ); - thisNode = iterator.iterateNext(); - } -} -catch (e) { - alert( 'Error: Document tree modified during iteration ' + e ); -} -</pre> - -<h5 id="Snapshots" name="Snapshots">Snapshots</h5> - -<p>When the specified result type in the <code>resultType</code> parameter is either:</p> - -<ul> - <li><code>UNORDERED_NODE_SNAPSHOT_TYPE</code></li> - <li><code>ORDERED_NODE_SNAPSHOT_TYPE</code></li> -</ul> - -<p>The <code>XPathResult</code> object returned is a static node-set of matched nodes, which allows us to access each node through the <code>snapshotItem(itemNumber)</code> method of the <code>XPathResult</code> object, where <code>itemNumber</code> is the index of the node to be retrieved. The total number of nodes contained can be accessed through the <code>snapshotLength</code> property.</p> - -<p>Snapshots do not change with document mutations, so unlike the iterators, the snapshot does not become invalid, but it may not correspond to the current document, for example, the nodes may have been moved, it might contain nodes that no longer exist, or new nodes could have been added.</p> - -<h6 id="Snapshot_Example" name="Snapshot_Example">Snapshot Example</h6> - -<pre class="brush: js notranslate">var nodesSnapshot = document.evaluate('//phoneNumber', documentNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); - -for ( var i=0 ; i < nodesSnapshot.snapshotLength; i++ ) -{ - alert( nodesSnapshot.snapshotItem(i).textContent ); -} -</pre> - -<h5 id="First_Node" name="First_Node">First Node</h5> - -<p>When the specified result type in the <code>resultType</code> parameter is either:</p> - -<ul> - <li><code>ANY_UNORDERED_NODE_TYPE</code></li> - <li><code>FIRST_ORDERED_NODE_TYPE</code></li> -</ul> - -<p>The <code>XPathResult</code> object returned is only the first found node that matched the XPath expression. This can be accessed through the <code>singleNodeValue</code> property of the <code>XPathResult</code> object. This will be <code>null</code> if the node set is empty.</p> - -<p>Note that, for the unordered subtype the single node returned might not be the first in document order, but for the ordered subtype you are guaranteed to get the first matched node in the document order.</p> - -<h6 id="First_Node_Example" name="First_Node_Example">First Node Example</h6> - -<pre class="brush: js notranslate">var firstPhoneNumber = document.evaluate('//phoneNumber', documentNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); - -alert( 'The first phone number found is ' + firstPhoneNumber.singleNodeValue.textContent ); -</pre> - -<h4 id="The_ANY_TYPE_Constant" name="The_ANY_TYPE_Constant">The ANY_TYPE Constant</h4> - -<p>When the result type in the <code>resultType</code> parameter is specified as <code>ANY_TYPE</code>, the <code>XPathResult</code> object returned, will be whatever type that naturally results from the evaluation of the expression.</p> - -<p>It could be any of the simple types (<code>NUMBER_TYPE, STRING_TYPE, BOOLEAN_TYPE</code>), <strong>but</strong>, if the returned result type is a node-set then it will <strong>only</strong> be an <code>UNORDERED_NODE_ITERATOR_TYPE</code>.</p> - -<p>To determine that type after evaluation, we use the <code>resultType</code> property of the <code>XPathResult</code> object. The <a href="#XPathResult_Defined_Constants">constant</a> values of this property are defined in the appendix. <span class="comment">None Yet =====Any_Type Example===== <pre> </pre></span></p> - -<h2 id="Examples" name="Examples">Examples</h2> - -<h3 id="Within_an_HTML_Document" name="Within_an_HTML_Document">Within an HTML Document</h3> - -<p>The following code is intended to be placed in any JavaScript fragment within or linked to the HTML document against which the XPath expression is to be evaluated.</p> - -<p>To extract all the <code><h2></code> heading elements in an HTML document using XPath, the <code>xpathExpression</code> is simply '<code>//h2</code>'. Where, <code>//</code> is the Recursive Descent Operator that matches elements with the nodeName <code>h2</code> anywhere in the document tree. The full code for this is: <span class="comment">link to introductory xpath doc</span></p> - -<pre class="brush: js notranslate">var headings = document.evaluate('//h2', document, null, XPathResult.ANY_TYPE, null ); -</pre> - -<p>Notice that, since HTML does not have namespaces, we have passed <code>null</code> for the <code>namespaceResolver</code> parameter.</p> - -<p>Since we wish to search over the entire document for the headings, we have used the <a href="/en-US/docs/Web/API/document" title="en/DOM/document">document</a> object itself as the <code>contextNode</code>.</p> - -<p>The result of this expression is an <code>XPathResult</code> object. If we wish to know the type of result returned, we may evaluate the <code>resultType</code> property of the returned object. In this case, that will evaluate to <code>4</code>, an <code>UNORDERED_NODE_ITERATOR_TYPE</code>. This is the default return type when the result of the XPath expression is a node set. It provides access to a single node at a time and may not return nodes in a particular order. To access the returned nodes, we use the <code>iterateNext()</code> method of the returned object:</p> - -<pre class="brush: js notranslate">var thisHeading = headings.iterateNext(); - -var alertText = 'Level 2 headings in this document are:\n' - -while (thisHeading) { - alertText += thisHeading.textContent + '\n'; - thisHeading = headings.iterateNext(); -} -</pre> - -<p>Once we iterate to a node, we have access to all the standard DOM interfaces on that node. After iterating through all the <code>h2</code> elements returned from our expression, any further calls to <code>iterateNext()</code> will return <code>null</code>.</p> - -<h3 id="Evaluating_against_an_XML_document_within_an_Extension" name="Evaluating_against_an_XML_document_within_an_Extension">Evaluating against an XML document within an Extension</h3> - -<p>The following uses an XML document located at <span class="nowiki">chrome://yourextension/content/peopleDB.xml</span> as an example.</p> - -<pre class="brush: xml notranslate"><?xml version="1.0"?> -<people xmlns:xul = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" > - <person> - <name first="george" last="bush" /> - <address street="1600 pennsylvania avenue" city="washington" country="usa"/> - <phoneNumber>202-456-1111</phoneNumber> - </person> - <person> - <name first="tony" last="blair" /> - <address street="10 downing street" city="london" country="uk"/> - <phoneNumber>020 7925 0918</phoneNumber> - </person> -</people> -</pre> - -<p>To make the contents of the XML document available within the extension, we create an <code><a href="/en-US/docs/Web/API/XMLHttpRequest" title="en/XMLHttpRequest">XMLHttpRequest</a></code> object to load the document synchronously, the variable <code>xmlDoc</code> will contain the document as an <code><a href="/en-US/docs/Web/API/XMLDocument" title="en/XMLDocument">XMLDocument</a></code> object against which we can use the <code>evaluate</code> method</p> - -<p>JavaScript used in the extensions xul/js documents.</p> - -<pre class="brush: js notranslate">var req = new XMLHttpRequest(); - -req.open("GET", "chrome://yourextension/content/peopleDB.xml", false); -req.send(null); - -var xmlDoc = req.responseXML; - -var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement); - -var personIterator = xmlDoc.evaluate('//person', xmlDoc, nsResolver, XPathResult.ANY_TYPE, null ); -</pre> - -<h3 id="Note">Note</h3> - -<p>When the XPathResult object is not defined, the constants can be retrieved in privileged code using <code>Components.interfaces.nsIDOMXPathResult.ANY_TYPE</code> (<code>CI.nsIDOMXPathResult</code>). Similarly, an XPathEvaluator can be created using:</p> - -<pre class="brush: js notranslate">Components.classes["@mozilla.org/dom/xpath-evaluator;1"].createInstance(Components.interfaces.nsIDOMXPathEvaluator)</pre> - -<h2 id="Appendix" name="Appendix">Appendix</h2> - -<h4 id="Implementing_a_User_Defined_Namespace_Resolver" name="Implementing_a_User_Defined_Namespace_Resolver">Implementing a User Defined Namespace Resolver</h4> - -<p>This is an example for illustration only. This function will need to take namespace prefixes from the <code>xpathExpression</code> and return the URI that corresponds to that prefix. For example, the expression:</p> - -<pre class="notranslate">'//xhtml:td/mathml:math' -</pre> - -<p>will select all <a href="/en-US/docs/Web/API/MathML" title="en/MathML">MathML</a> expressions that are the children of (X)HTML table data cell elements.</p> - -<p>In order to associate the '<code>mathml:</code>' prefix with the namespace URI '<code><span class="nowiki">http://www.w3.org/1998/Math/MathML</span></code>' and '<code>xhtml:</code>' with the URI '<code><span class="nowiki">http://www.w3.org/1999/xhtml</span></code>' we provide a function:</p> - -<pre class="brush: js notranslate">function nsResolver(prefix) { - var ns = { - 'xhtml' : 'http://www.w3.org/1999/xhtml', - 'mathml': 'http://www.w3.org/1998/Math/MathML' - }; - return ns[prefix] || null; -} -</pre> - -<p>Our call to <code>document.evaluate</code> would then looks like:</p> - -<pre class="brush: js notranslate">document.evaluate( '//xhtml:td/mathml:math', document, nsResolver, XPathResult.ANY_TYPE, null ); -</pre> - -<h4 id="Implementing_a_default_namespace_for_XML_documents" name="Implementing_a_default_namespace_for_XML_documents">Implementing a default namespace for XML documents</h4> - -<p>As noted in the <a href="#Implementing_a_Default_Namespace_Resolver">Implementing a Default Namespace Resolver</a> previously, the default resolver does not handle the default namespace for XML documents. For example with this document:</p> - -<pre class="brush: xml notranslate"><?xml version="1.0" encoding="UTF-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - <entry /> - <entry /> - <entry /> -</feed> -</pre> - -<p><code>doc.evaluate('//entry', doc, nsResolver, XPathResult.ANY_TYPE, null)</code> will return an empty set, where <code>nsResolver</code> is the resolver returned by <code>createNSResolver</code>. Passing a <code>null</code> resolver doesn't work any better, either.</p> - -<p>One possible workaround is to create a custom resolver that returns the correct default namespace (the Atom namespace in this case). Note that you still have to use some namespace prefix in your XPath expression, so that the resolver function will be able to change it to your required namespace. E.g.:</p> - -<pre class="brush: js notranslate">function resolver() { - return 'http://www.w3.org/2005/Atom'; -} -doc.evaluate('//myns:entry', doc, resolver, XPathResult.ANY_TYPE, null) -</pre> - -<p>Note that a more complex resolver will be required if the document uses multiple namespaces.</p> - -<p>An approach which might work better (and allow namespaces not to be known ahead of time) is described in the next section.</p> - -<h4 id="Using_XPath_functions_to_reference_elements_with_a_default_namespace" name="Using_XPath_functions_to_reference_elements_with_a_default_namespace">Using XPath functions to reference elements with a default namespace</h4> - -<p>Another approach to match default elements in a non-null namespace (and one which works well for dynamic XPath expressions where the namespaces might not be known), involves referring to a particular element using a form such as <code>[namespace-uri()='<span class="nowiki">http://www.w3.org/1999/xhtml</span>' and name()='p' and @id='_myid']</code>. This circumvents the problem of an XPath query not being able to detect the default namespace on a regularly labeled element.</p> - -<h4 id="Getting_specifically_namespaced_elements_and_attributes_regardless_of_prefix" name="Getting_specifically_namespaced_elements_and_attributes_regardless_of_prefix">Getting specifically namespaced elements and attributes regardless of prefix</h4> - -<p>If one wishes to provide flexibility in namespaces (as they are intended) by not necessarily requiring a particular prefix to be used when finding a namespaced element or attribute, one must use special techniques.</p> - -<p>While one can adapt the approach in the above section to test for namespaced elements regardless of the prefix chosen (using <code><a href="/en-US/docs/XPath/Functions/local-name" title="en/XPath/Functions/local-name">local-name()</a></code> in combination with <code><a href="/en-US/docs/XPath/Functions/namespace-uri" title="en/XPath/Functions/namespace-uri">namespace-uri()</a></code> instead of <code><a href="/en-US/docs/XPath/Functions/name" title="en/XPath/Functions/name">name()</a></code>), a more challenging situation occurs, however, if one wishes to grab an element with a particular namespaced attribute in a predicate (given the absence of implementation-independent variables in XPath 1.0).</p> - -<p>For example, one might try (incorrectly) to grab an element with a namespaced attribute as follows: <code>var xpathlink = someElements[local-name(@*)="href" and namespace-uri(@*)='<span class="nowiki">http://www.w3.org/1999/xlink</span>'];</code></p> - -<p>This could inadvertently grab some elements if one of its attributes existed that had a local name of "<code>href</code>", but it was a different attribute which had the targeted (XLink) namespace (instead of <code><a href="/en/XPath/Axes/attribute" title="en/XPath/Axes/attribute">@href</a></code>).</p> - -<p>In order to accurately grab elements with the XLink <code>@href</code> attribute (without also being confined to predefined prefixes in a namespace resolver), one could obtain them as follows:</p> - -<pre class="brush: js notranslate">var xpathEls = 'someElements[@*[local-name() = "href" and namespace-uri() = "http://www.w3.org/1999/xlink"]]'; // Grabs elements with any single attribute that has both the local name 'href' and the XLink namespace -var thislevel = xml.evaluate(xpathEls, xml, null, XPathResult.ANY_TYPE, null); -var thisitemEl = thislevel.iterateNext(); -</pre> - -<h4 id="XPathResult_Defined_Constants" name="XPathResult_Defined_Constants">XPathResult Defined Constants</h4> - -<table class="standard-table"> - <thead> - <tr> - <td class="header">Result Type Defined Constant</td> - <td class="header">Value</td> - <td class="header">Description</td> - </tr> - </thead> - <tbody> - <tr> - <td>ANY_TYPE</td> - <td>0</td> - <td>A result set containing whatever type naturally results from the evaluation of the expression. Note that if the result is a node-set then UNORDERED_NODE_ITERATOR_TYPE is always the resulting type.</td> - </tr> - <tr> - <td>NUMBER_TYPE</td> - <td>1</td> - <td>A result containing a single number. This is useful for example, in an XPath expression using the <code>count()</code> function.</td> - </tr> - <tr> - <td>STRING_TYPE</td> - <td>2</td> - <td>A result containing a single string.</td> - </tr> - <tr> - <td>BOOLEAN_TYPE</td> - <td>3</td> - <td>A result containing a single boolean value. This is useful for example, in an XPath expression using the <code>not()</code> function.</td> - </tr> - <tr> - <td>UNORDERED_NODE_ITERATOR_TYPE</td> - <td>4</td> - <td>A result node-set containing all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document.</td> - </tr> - <tr> - <td>ORDERED_NODE_ITERATOR_TYPE</td> - <td>5</td> - <td>A result node-set containing all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document.</td> - </tr> - <tr> - <td>UNORDERED_NODE_SNAPSHOT_TYPE</td> - <td>6</td> - <td>A result node-set containing snapshots of all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document.</td> - </tr> - <tr> - <td>ORDERED_NODE_SNAPSHOT_TYPE</td> - <td>7</td> - <td>A result node-set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document.</td> - </tr> - <tr> - <td>ANY_UNORDERED_NODE_TYPE</td> - <td>8</td> - <td>A result node-set containing any single node that matches the expression. The node is not necessarily the first node in the document that matches the expression.</td> - </tr> - <tr> - <td>FIRST_ORDERED_NODE_TYPE</td> - <td>9</td> - <td>A result node-set containing the first node in the document that matches the expression.</td> - </tr> - </tbody> -</table> - -<h2 id="See_also" name="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/XPath">XPath</a></li> - <li><a href="http://www.xml.com/pub/a/2000/08/holman/index.html?page=2#xpath-info">XML Path Language </a>from <em><a href="http://www.xml.com/pub/a/2000/08/holman/">What is XSLT?</a> </em>by G. Ken Holman</li> -</ul> - -<div class="originaldocinfo"> -<h2 id="Original_Document_Information" name="Original_Document_Information">Original Document Information</h2> - -<ul> - <li>Based Upon Original Document <a class="external" href="http://www-xray.ast.cam.ac.uk/~jgraham/mozilla/xpath-tutorial.html">Mozilla XPath Tutorial</a></li> - <li>Original Source Author: James Graham.</li> - <li>Other Contributors: James Thompson.</li> - <li>Last Updated Date: 2006-3-25.</li> -</ul> -</div> diff --git a/files/ja/web/javascript/reference/global_objects/array/index/index.html b/files/ja/web/javascript/reference/global_objects/array/index/index.html deleted file mode 100644 index 1d2e7a4797..0000000000 --- a/files/ja/web/javascript/reference/global_objects/array/index/index.html +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: index -slug: Web/JavaScript/Reference/Global_Objects/Array/index ---- -<h2 id="Summary" name="Summary">概要</h2> -<p>正規表現マッチにより作成された配列において、文字列中での一致部分の、0 から始まるインデックス。</p> -<table class="standard-table"> - <thead> - <tr> - <td class="header" colspan="2"><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> のプロパティ</td> - </tr> - </thead> - <tbody> - <tr> - <td colspan="2"><b>静的</b></td> - </tr> - <tr> - <td>実装されたバージョン</td> - <td>JavaScript 1.2</td> - </tr> - </tbody> -</table> diff --git a/files/ja/web/javascript/reference/global_objects/array/input/index.html b/files/ja/web/javascript/reference/global_objects/array/input/index.html deleted file mode 100644 index 166ed28656..0000000000 --- a/files/ja/web/javascript/reference/global_objects/array/input/index.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: input -slug: Web/JavaScript/Reference/Global_Objects/Array/input ---- -<p> -</p><p>{{ 英語版章題("Summary") }} -</p> -<h3 id=".E6.A6.82.E8.A6.81" name=".E6.A6.82.E8.A6.81"> 概要 </h3> -<p>正規表現マッチにより作成された配列において、正規表現がマッチを行った元の文字列を反映します。 -</p> -<table class="fullwidth-table"> -<tbody><tr> -<td class="header" colspan="2"><a href="ja/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a> のプロパティ</td> -</tr> -<tr> -<td colspan="2"><b>静的</b></td> -</tr> -<tr> -<td>実装されたバージョン:</td> -<td>JavaScript 1.2, NES 3.0</td> -</tr> -</tbody></table> -<div class="noinclude"> -</div> -{{ languages( { "en": "en/Core_JavaScript_1.5_Reference/Global_Objects/Array/input", "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globaux/Array/input", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Array/input" } ) }} diff --git a/files/ja/web/javascript/reference/global_objects/array/prototype/index.html b/files/ja/web/javascript/reference/global_objects/array/prototype/index.html deleted file mode 100644 index dc20c31a41..0000000000 --- a/files/ja/web/javascript/reference/global_objects/array/prototype/index.html +++ /dev/null @@ -1,176 +0,0 @@ ---- -title: Array.prototype -slug: Web/JavaScript/Reference/Global_Objects/Array/prototype -tags: - - Array - - JavaScript - - Junk - - Property -translation_of: Web/JavaScript/Reference/Global_Objects/Array/prototype ---- -<div>{{JSRef}}</div> - -<h2 id="Description" name="Description">解説</h2> - -<p>{{jsxref("Array")}} インスタンスは、 <code>Array.prototype</code> を継承しています。すべてのコンストラクターと同様に、コンストラクターの prototype オブジェクトを変更して、すべての {{jsxref("Array")}} インスタンスを変更することができます。例えば、新しいメソッドやプロパティを追加して、すべての <code>Array</code> オブジェクトを拡張することができます。例えば、これは{{Glossary("Polyfill", "ポリフィル")}}に使用されます。</p> - -<p>ただし、配列オブジェクトに標準外メソッドを追加すると、後で独自のコードに問題が発生したり、 <a href="https://developers.google.com/web/updates/2018/03/smooshgate">JavaScript への機能の追加</a>の際に問題が発生することがあります。</p> - -<p>豆知識: <code>Array.prototype</code> はそれ自体が {{jsxref("Array")}} です。</p> - -<pre class="brush: js notranslate">Array.isArray(Array.prototype); // true -</pre> - -<p>{{js_property_attributes(0, 0, 0)}}</p> - -<h2 id="Properties" name="Properties">プロパティ</h2> - -<dl> - <dt><code>Array.prototype.constructor</code></dt> - <dd>オブジェクトの prototype を生成する関数を指定します。</dd> - <dt>{{jsxref("Array.prototype.length")}}</dt> - <dd>配列内の要素数を反映します。</dd> - <dt>{{jsxref("Array.@@unscopables", "Array.prototype[@@unscopables]")}}</dt> - <dd><code><a href="/ja/docs/Web/JavaScript/Reference/Statements/with">with</a></code> バインディングのスコープから除外されるプロパティ名を保持するシンボル。</dd> -</dl> - -<h2 id="Methods" name="Methods">メソッド</h2> - -<h3 id="Mutator_methods" name="Mutator_methods">Mutator メソッド</h3> - -<p>これらのメソッドは、配列を書き換えます。</p> - -<dl> - <dt>{{jsxref("Array.prototype.copyWithin()")}}</dt> - <dd>配列内で配列内の連続した要素をコピーします。</dd> - <dt>{{jsxref("Array.prototype.fill()")}}</dt> - <dd>配列内の指定した開始位置から終了位置までの要素を固定値で埋めます。</dd> - <dt>{{jsxref("Array.prototype.pop()")}}</dt> - <dd>配列から最後の要素を取り除き、戻り値として返します。</dd> - <dt>{{jsxref("Array.prototype.push()")}}</dt> - <dd>配列の最後に 1 個以上の要素を追加し、新しい配列の長さを返します。</dd> - <dt>{{jsxref("Array.prototype.reverse()")}}</dt> - <dd>配列の要素の順番を逆転させます (最初の要素は最後に、最後の要素は最初になります)。</dd> - <dt>{{jsxref("Array.prototype.shift()")}}</dt> - <dd>配列から最初の要素を取り除き、その要素を返します。</dd> - <dt>{{jsxref("Array.prototype.sort()")}}</dt> - <dd>配列内で要素を整列し、配列を返します。</dd> - <dt>{{jsxref("Array.prototype.splice()")}}</dt> - <dd>配列に対して複数の要素を追加したり取り除いたりします。</dd> - <dt>{{jsxref("Array.prototype.unshift()")}}</dt> - <dd>配列の最初に 1 個以上の要素を追加し、配列の変更後の長さを返します。</dd> -</dl> - -<h3 id="Accessor_methods" name="Accessor_methods">アクセサーメソッド</h3> - -<p>これらのメソッドは呼び出し対象の配列を書き換えず、配列を何らかの形で表したものを返します。</p> - -<dl> - <dt>{{jsxref("Array.prototype.concat()")}}</dt> - <dd>この配列に他の配列や値を結合して新しい配列を返します。</dd> - <dt>{{jsxref("Array.prototype.includes()")}}</dt> - <dd>この配列が特定の要素を含むかどうか判定し、その結果を <code>true</code> または <code>false</code> で返します。</dd> - <dt>{{jsxref("Array.prototype.indexOf()")}}</dt> - <dd>指定された値と等しい値を持つ最初の (添字の一番小さい) 要素の添字を返します。見つからない場合、-1 を返します。</dd> - <dt>{{jsxref("Array.prototype.join()")}}</dt> - <dd>配列のすべての要素を結合した文字列を返します。</dd> - <dt>{{jsxref("Array.prototype.lastIndexOf()")}}</dt> - <dd>指定された値と等しい値を持つ最後の (添字の一番大きい) 要素の添字を返します。見つからない場合、-1 を返します。</dd> - <dt>{{jsxref("Array.prototype.slice()")}}</dt> - <dd>配列の一部を取り出して新しい配列として返します。</dd> - <dt>{{jsxref("Array.prototype.toSource()")}} {{non-standard_inline}}</dt> - <dd>指定された配列を表す配列リテラルを返します。この値を使って新しい配列を作れます。{{jsxref("Object.prototype.toSource()")}} メソッドを上書きしています。</dd> - <dt>{{jsxref("Array.prototype.toString()")}}</dt> - <dd>配列とその要素を表す文字列を返します。{{jsxref("Object.prototype.toString()")}} メソッドを上書きしています。</dd> - <dt>{{jsxref("Array.prototype.toLocaleString()")}}</dt> - <dd>配列とその要素を表すロケールに従った文字列を返します。{{jsxref("Object.prototype.toLocaleString()")}} メソッドを上書きしています。</dd> -</dl> - -<h3 id="Iteration_methods" name="Iteration_methods">反復メソッド</h3> - -<p>いくつかのメソッドは、配列を処理する際にコールバックされる関数を引数に取ります。これらのメソッドが呼ばれる時、配列の <code>length</code> 値を一時記憶するため、コールバック中にこの長さを超えて追加された要素にはアクセスしません。配列に対するその他の変更 (要素の値の書き換えや削除) は、変更された要素にメソッドが後でアクセスした場合の操作結果に影響を及ぼす可能性があります。そのような場合におけるこれらのメソッドの振る舞いは正確に定義されていますが、コードの読者を混乱させないよう、その振る舞いに依存すべきではありません。配列を変化させなければならない場合は、代わりに新しい配列にコピーしてください。</p> - -<dl> - <dt>{{jsxref("Array.prototype.entries()")}}</dt> - <dd>新しい <code>Array Iterator</code> オブジェクトを返します。このオブジェクトは、配列中の各インデックスに対する key/value ペアを保持しています。</dd> - <dt>{{jsxref("Array.prototype.every()")}}</dt> - <dd>指定したテスト関数を配列中のすべての要素が満たした場合に <code>true</code> を返します。</dd> - <dt>{{jsxref("Array.prototype.filter()")}}</dt> - <dd>指定したフィルタリング関数が <code>true</code> を返す、配列中の要素を格納した新しい配列を生成します。</dd> - <dt>{{jsxref("Array.prototype.find()")}}</dt> - <dd>指定したテスト関数を満たす、配列中の要素の値を返します。1 個も見つからない場合は <code>undefined</code> を返します。</dd> - <dt>{{jsxref("Array.prototype.findIndex()")}}</dt> - <dd>指定したテスト関数を満たす、配列中の要素のインデックスを返します。1 個も見つからない場合は <code>-1</code> を返します。</dd> - <dt>{{jsxref("Array.prototype.forEach()")}}</dt> - <dd>配列中のそれぞれの要素について関数を呼び出します。</dd> - <dt>{{jsxref("Array.prototype.keys()")}}</dt> - <dd>新しい <code>Array Iterator</code> を返します。このオブジェクトは配列中の各インデックスのキーを保持します。</dd> - <dt>{{jsxref("Array.prototype.map()")}}</dt> - <dd>配列内のすべての要素に対して与えられた関数を呼び出し、その結果を格納した新しい配列を生成します。</dd> - <dt>{{jsxref("Array.prototype.reduce()")}}</dt> - <dd>アキュムレータと配列内のすべての要素に対して (左から右の順で) 関数を適用し、単一の値に還元します。</dd> - <dt>{{jsxref("Array.prototype.reduceRight()")}}</dt> - <dd>アキュムレータと配列内のすべての要素に対して (右から左の順で) 関数を適用し、単一の値に還元します。</dd> - <dt>{{jsxref("Array.prototype.some()")}}</dt> - <dd>指定したテスト関数を配列中の少なくとも 1 個の要素が満たした場合に <code>true</code> を返します。</dd> - <dt>{{jsxref("Array.prototype.values()")}}</dt> - <dd>新しい <code>Array Iterator</code> オブジェクトを返します。このオブジェクトは、配列中の各インデックスの値を保持します。</dd> - <dt>{{jsxref("Array.prototype.@@iterator()", "Array.prototype[@@iterator]()")}}</dt> - <dd>新しい <code>Array Iterator</code> オブジェクトを返します。このオブジェクトは、配列中の各インデックスの値を保持します。</dd> -</dl> - -<h3 id="Generic_methods_non-standard" name="Generic_methods_(non-standard)">ジェネリックメソッド (非標準)</h3> - -<p>JavaScript の <code>Array</code> オブジェクト上の多くのメソッドは、配列型 (array-like) のあらゆるオブジェクトに対し広く適用されるよう設計されています。すなわち、どんなオブジェクトでも <code>length</code> プロパティを持ち、数値プロパティ名を使う (<code>array[5]</code> のような) アクセスが有効なら、それらを適用できます。{{jsxref("Array.join", "join")}} のような一部のメソッドは、呼び出し対象オブジェクトの <code>length</code> や数値プロパティを読み取るだけです。 一方、{{jsxref("Array.reverse", "reverse")}} のようなメソッドは、対象オブジェクトの数値プロパティや <code>length</code> が変更可能であることを要求するため、<code>length</code> プロパティや設定される合成数値プロパティの変更を許さない {{jsxref("String")}} のようなオブジェクトに対して呼び出すことができません。</p> - -<h2 id="Specifications" name="Specifications">仕様書</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様書</th> - <th scope="col">状態</th> - <th scope="col">備考</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>初回定義</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-15.4.3.1', 'Array.prototype')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-array.prototype', 'Array.prototype')}}</td> - <td>{{Spec2('ES6')}}</td> - <td><code>copyWithin()</code>, <code>fill()</code>, <code>entries()</code>, <code>keys()</code>, <code>values()</code>, <code>find()</code>, <code>findIndex()</code> メソッドを追加</td> - </tr> - <tr> - <td>{{SpecName('ES7', '#sec-array.prototype', 'Array.prototype')}}</td> - <td>{{Spec2('ES7')}}</td> - <td><code>includes()</code> メソッドを追加</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-array.prototype', 'Array.prototype')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2> - -<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> - -<p>{{Compat("javascript.builtins.Array.prototype")}}</p> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li>{{jsxref("Array")}}</li> - <li>{{jsxref("Function.prototype")}}</li> -</ul> diff --git a/files/ja/web/javascript/reference/global_objects/asyncfunction/prototype/index.html b/files/ja/web/javascript/reference/global_objects/asyncfunction/prototype/index.html deleted file mode 100644 index 46bf817819..0000000000 --- a/files/ja/web/javascript/reference/global_objects/asyncfunction/prototype/index.html +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: AsyncFunction.prototype -slug: Web/JavaScript/Reference/Global_Objects/AsyncFunction/prototype -tags: - - Experimental - - JavaScript - - Property - - Prototype - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/AsyncFunction/prototype ---- -<div>{{JSRef}}</div> - -<p><code><strong>AsyncFunction.prototype</strong></code> プロパティは、{{jsxref("AsyncFunction")}} プロトタイプオブジェクトを表します。</p> - -<h2 id="説明">説明</h2> - -<p>{{jsxref("AsyncFunction")}} オブジェクトは、<code>AsyncFunction.prototype</code> を継承します。<code>AsyncFunction.prototype</code> は修正できません。</p> - -<h2 id="プロパティ">プロパティ</h2> - -<dl> - <dt><code><strong>AsyncFunction.constructor</strong></code></dt> - <dd>初期値は {{jsxref("AsyncFunction")}}。</dd> - <dt><code><strong>AsyncFunction.prototype[@@toStringTag]</strong></code></dt> - <dd>"AsyncFunction" を返す。</dd> -</dl> - -<h2 id="仕様">仕様</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様</th> - <th scope="col">ステータス</th> - <th scope="col">コメント</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('Async Function', '#async-function-definitions', 'async function')}}</td> - <td>{{Spec2('Async Function')}}</td> - <td>提案</td> - </tr> - </tbody> -</table> - -<h2 id="ブラウザー実装状況">ブラウザー実装状況</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>機能</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th> Edge</th> - <th>Opera</th> - <th>Safari (WebKit)</th> - </tr> - <tr> - <td>基本サポート</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoDesktop("52.0")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>機能</th> - <th>Android</th> - <th>Android Webview</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - <th>Chrome for Android</th> - </tr> - <tr> - <td>基本サポート</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoMobile("52.0")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="関連項目">関連項目</h2> - -<ul> - <li>{{jsxref("AsyncFunction")}}</li> - <li>{{jsxref("Function")}}</li> -</ul> diff --git a/files/ja/web/javascript/reference/global_objects/atomics/wake/index.html b/files/ja/web/javascript/reference/global_objects/atomics/notify/index.html index be17a5f891..9595b04f3d 100644 --- a/files/ja/web/javascript/reference/global_objects/atomics/wake/index.html +++ b/files/ja/web/javascript/reference/global_objects/atomics/notify/index.html @@ -1,7 +1,8 @@ --- title: Atomics.wake() -slug: Web/JavaScript/Reference/Global_Objects/Atomics/wake +slug: Web/JavaScript/Reference/Global_Objects/Atomics/notify translation_of: Web/JavaScript/Reference/Global_Objects/Atomics/notify +original_slug: Web/JavaScript/Reference/Global_Objects/Atomics/wake --- <div>{{JSRef}} {{SeeCompatTable}}</div> diff --git a/files/ja/web/javascript/reference/global_objects/finalizationregistry/cleanupsome/index.html b/files/ja/web/javascript/reference/global_objects/finalizationregistry/cleanupsome/index.html deleted file mode 100644 index c25d3dd476..0000000000 --- a/files/ja/web/javascript/reference/global_objects/finalizationregistry/cleanupsome/index.html +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: FinalizationRegistry.prototype.cleanupSome() -slug: Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/cleanupSome -tags: - - FinalizationRegistry - - JavaScript - - Method - - Prototype - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/cleanupSome ---- -<div>{{JSRef}}</div> - -<p><strong>cleanupSome()</strong> メソッドは、 {{jsxref("FinalizationRegistry")}} 内のオブジェクトのうち、まだコールバックが呼ばれていないが回収されているオブジェクトの数が実装で選択された場合に、クリーンアップコールバックを起動します。このメソッドはオプションです。</p> - -<h2 id="Syntax" name="Syntax">構文</h2> - -<pre class="syntaxbox notranslate"><code><var>registry</var>.cleanupSome([<var>callback</var>]);</code> -</pre> - -<h3 id="Parameters" name="Parameters">引数</h3> - -<dl> - <dt><code><var>callback</var></code> {{optional_inline}}</dt> - <dd>この <code>cleanupSome</code> への呼び出しによって起動されるコールバックだけに使用するコールバックを指定します。指定した場合、このコールバックは <code>FinalizationRegistry</code> で作成されたものの代わりに使用されます。</dd> -</dl> - -<h3 id="Return_value" name="Return_value">返値</h3> - -<p><code>undefined</code> です。</p> - -<h2 id="Notes" name="Notes">注</h2> - -<p>通常、この関数を呼び出すことはありません。コールバックを適切に行うためには、 JavaScript エンジンのガベージコレクターに任せてください。この関数は主に、イベントループを発生させない、通常の JavaScript コードよりも WebAssembly で出てくる可能性の高い、長期に実行されるコードに対応するために存在します。また、コールバックが呼び出されない場合があることにも注意してください (例えば、ターゲットが回収されたレジストリ項目が存在しない場合)。</p> - -<p>レジストリからクリーンアップされる (クリーンアップコールバックを呼び出す) 回収オブジェクトの項目数は、実装で定義されています。実装によっては、対象となる項目を一つだけ削除したり、対象となるすべての項目を削除したり、あるいはその間のどこかで削除したりすることもあります。</p> - -<h2 id="Examples" name="Examples">例</h2> - -<h3 id="Using_cleanupSome" name="Using_cleanupSome">cleanupSome の使用</h3> - -<pre class="brush: js notranslate">registry.cleanupSome?.(heldValue => { - // ... -}); -</pre> - -<p>このメソッドはオプションであり、実装によってはこのメソッドを持たない場合があります。詳細は <a href="https://github.com/whatwg/html/issues/5446">HTML issue #5446</a> を参照してください。このメソッドはオプションなので、それを呼び出す前にそのメソッドが存在することを確認する必要があります。そのための一つの方法は、上の例のように<a href="/ja/docs/Web/JavaScript/Reference/Operators/Optional_chaining">オプション連結</a> (<code>?.</code>) を使用することです。</p> - -<h2 id="Specifications" name="Specifications">仕様書</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様書</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('WeakRefs', '#sec-finalization-registry.prototype.cleanupSome', 'FinalizationRegistry.prototype.cleanupSome')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> - -<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> - -<p>{{Compat("javascript.builtins.FinalizationRegistry.cleanupSome")}}</p> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li>{{jsxref("FinalizationRegistry")}}</li> -</ul> diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html deleted file mode 100644 index 5705852c36..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/prototype/index.html +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: Intl.DateTimeFormat.prototype -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/prototype -tags: - - DateTimeFormat - - Internationalization - - JavaScript - - Property - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat -translation_of_original: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/prototype ---- -<div>{{JSRef}}</div> - -<p><strong><code>Intl.DateTimeFormat.prototype</code></strong> プロパティは、 {{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}} コンストラクターに対するプロトタイプオブジェクトを表します。</p> - -<div>{{js_property_attributes(0, 0, 0)}}</div> - -<h2 id="Description" name="Description">解説</h2> - -<p><code>Intl.DateTimeFormat</code> インスタンスの解説については {{jsxref("DateTimeFormat")}} を確認して下さい。</p> - -<p>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} インスタンスは <code>Intl.DateTimeFormat.prototype</code> から継承します。プロトタイプオブジェクトへの変更はすべての {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} インスタンスによって継承されます。</p> - -<h2 id="Properties" name="Properties">プロパティ</h2> - -<dl> - <dt><code>Intl.DateTimeFormat.prototype.constructor</code></dt> - <dd>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} への参照です。</dd> -</dl> - -<h2 id="Methods" name="Methods">メソッド</h2> - -<dl> - <dt>{{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format()")}}</dt> - <dd>ロケールおよびこの {{jsxref("DateTimeFormat", "DateTimeFormat")}} オブジェクトの書式化オプションに則って日付を書式化するゲッター関数です。</dd> - <dt>{{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}</dt> - <dd>Returns an {{jsxref("Array")}} of objects representing the date string in parts that can be used for custom locale-aware formatting.</dd> - <dt>{{jsxref("DateTimeFormat.resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}</dt> - <dd>ローケルを反映しているプロパティとオブジェクトの初期化中に計算されたオプションをもった新しいオブジェクトを返します。</dd> - <dt>{{jsxref("DateTimeFormat.formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}}</dt> - <dd>This method receives two <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/">Dates</a> and formats the date range in the most concise way based on the locale and options provided when instantiating {{jsxref("DateTimeFormat", "DateTimeFormat")}}.</dd> - <dt>{{jsxref("DateTimeFormat.formatRangeToParts", "Intl.DateTimeFormat.prototype.formatRangeToParts()")}}</dt> - <dd>This method receives two <a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/">Dates</a> and returns an Array of objects containing the locale-specific tokens representing each part of the formatted date range.</dd> -</dl> - -<h2 id="Specifications" name="Specifications">仕様書</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様書</th> - <th scope="col">状態</th> - <th scope="col">備考</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ES Int Draft', '#sec-Intl.DateTimeFormat.prototype', 'Intl.DateTimeFormat.prototype')}}</td> - <td>{{Spec2('ES Int Draft')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES Int 2.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}</td> - <td>{{Spec2('ES Int 2.0')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES Int 1.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}</td> - <td>{{Spec2('ES Int 1.0')}}</td> - <td>初回定義</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> - -<div> -<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> - -<p>{{Compat("javascript.builtins.Intl.DateTimeFormat.prototype")}}</p> -</div> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li>{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}</li> -</ul> diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/instance/prototype/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/instance/prototype/index.html deleted file mode 100644 index fedccef945..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/instance/prototype/index.html +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: WebAssembly.Instance.prototype -slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/prototype -translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance -translation_of_original: Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/prototype ---- -<div>{{JSRef}} {{SeeCompatTable}}</div> - -<p><code><strong>WebAssembly.Instance</strong></code><strong><code>.prototype</code></strong> プロパティは {{jsxref("WebAssembly.Instance()")}} コンストラクタのプロトタイプを表します。</p> - -<div>{{js_property_attributes(0, 0, 0)}}</div> - -<h2 id="説明">説明</h2> - -<p>全ての {{jsxref("WebAssembly.Instance")}} インスタンスは <code>Instance.prototype</code> を継承します。{{jsxref("WebAssembly.Instance()")}} コンストラクタのプロトタイプオブジェクトは全ての {{jsxref( "WebAssembly.Instance")}} インスタンスに影響するように変更可能です。 </p> - -<h2 id="プロパティ">プロパティ</h2> - -<dl> - <dt><code>Instance.prototype.constructor</code></dt> - <dd>このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは {{jsxref("WebAssembly.Instance()")}} コンストラクタです。</dd> - <dt><code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports">Instance.prototype.exports</a></code> {{readonlyinline}}</dt> - <dd>WebAssembly モジュールインスタンスからエクスポートされた全ての関数をメンバとして持つオブジェクトを返します。これらは、JavaScriptからアクセスして使用することができます。</dd> -</dl> - -<h2 id="メソッド">メソッド</h2> - -<p>なし。</p> - -<h2 id="仕様">仕様</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様</th> - <th scope="col">策定状況</th> - <th scope="col">コメント</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('WebAssembly JS', '#webassemblymodule-objects', 'WebAssembly.Module()')}}</td> - <td>{{Spec2('WebAssembly JS')}}</td> - <td>初回ドラフト定義</td> - </tr> - </tbody> -</table> - -<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2> - -<div> - - -<p>{{Compat("javascript.builtins.WebAssembly.Instance.prototype")}}</p> -</div> - -<h2 id="関連情報">関連情報</h2> - -<ul> - <li>{{jsxref("WebAssembly.Instance()")}}</li> - <li><a href="/ja/docs/WebAssembly">WebAssembly</a> overview page</li> - <li><a href="/ja/docs/WebAssembly/Concepts">WebAssemblyのコンセプト</a></li> - <li><a href="/ja/docs/WebAssembly/Using_the_JavaScript_API">WebAssembly JavaScript API を使用する</a></li> -</ul> diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/memory/prototype/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/memory/prototype/index.html deleted file mode 100644 index 6d837f2f73..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/memory/prototype/index.html +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: WebAssembly.Memory.prototype -slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/prototype -tags: - - JavaScript - - Property - - Prototype - - WebAssembly - - memory -translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory -translation_of_original: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/prototype ---- -<div>{{JSRef}} {{SeeCompatTable}}</div> - -<p><code><strong>WebAssembly.Memory</strong></code><strong><code>.prototype</code></strong> プロパティは {{jsxref("WebAssembly.Memory()")}} コンストラクタのプロトタイプを表します。</p> - -<div>{{js_property_attributes(0, 0, 0)}}</div> - -<h2 id="説明">説明</h2> - -<p>全ての {{jsxref("WebAssembly.Memory")}} インスタンスは <code>Memory.prototype</code> を継承します。 {{jsxref("WebAssembly.Memory()")}} コンストラクタのプロトタイプオブジェクトは全ての {{jsxref( "WebAssembly.Memory")}} インスタンスに影響するように変更可能です。</p> - -<h2 id="プロパティ">プロパティ</h2> - -<dl> - <dt><code>Memory.prototype.constructor</code></dt> - <dd>このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは {{jsxref("WebAssembly.Memory()")}} コンストラクタです。</dd> - <dt>{{jsxref("WebAssembly/Memory/buffer","Memory.prototype.buffer")}}</dt> - <dd>メモリーに格納されているバッファを返すアクセサプロパティ。</dd> - <dt> - <h2 id="メソッド">メソッド</h2> - </dt> - <dt>{{jsxref("WebAssembly/Memory/grow","Memory.prototype.grow()")}}</dt> - <dd>指定した WebAssembly ページの数 (64KBを1単位とする) で <code>Memory</code> インスタンスのサイズを増やします。</dd> -</dl> - -<h2 id="仕様">仕様</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様</th> - <th scope="col">策定状況</th> - <th scope="col">コメント</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('WebAssembly JS', '#webassemblymemory-objects', 'Memory')}}</td> - <td>{{Spec2('WebAssembly JS')}}</td> - <td>初回ドラフト定義</td> - </tr> - </tbody> -</table> - -<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2> - -<div> - - -<p>{{Compat("javascript.builtins.WebAssembly.Memory.prototype")}}</p> -</div> - -<h2 id="関連情報">関連情報</h2> - -<ul> - <li>{{jsxref("WebAssembly.Memory()")}}</li> - <li><a href="/ja/docs/WebAssembly">WebAssembly</a> overview page</li> - <li><a href="/ja/docs/WebAssembly/Concepts">WebAssemblyのコンセプト</a></li> - <li><a href="/ja/docs/WebAssembly/Using_the_JavaScript_API">WebAssembly JavaScript API を使用する</a></li> -</ul> diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/table/prototype/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/table/prototype/index.html deleted file mode 100644 index 84709eb736..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/table/prototype/index.html +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: WebAssembly.Table.prototype -slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/prototype -tags: - - JavaScript - - Property - - Prototype - - WebAssembly - - table -translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table -translation_of_original: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/prototype ---- -<div>{{JSRef}} {{SeeCompatTable}}</div> - -<p><code><strong>WebAssembly.Table</strong></code><strong><code>.prototype</code></strong> プロパティは {{jsxref("WebAssembly.Table()")}} コンストラクタのプロトタイプを表します。</p> - -<div>{{js_property_attributes(0, 0, 0)}}</div> - -<h2 id="説明">説明</h2> - -<p>全ての {{jsxref("WebAssembly.Table")}} インスタンスは <code>Table.prototype</code> を継承します。{{jsxref("WebAssembly.Table()")}} コンストラクタのプロトタイプオブジェクトは全ての {{jsxref( "WebAssembly.Table")}} インスタンスに影響するように変更可能です。</p> - -<h2 id="プロパティ">プロパティ</h2> - -<dl> - <dt><code>Table.prototype.constructor</code></dt> - <dd>このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは {{jsxref("WebAssembly.Table()")}} コンストラクタです。</dd> - <dt>{{jsxref("WebAssembly/Table/length","Table.prototype.length")}}</dt> - <dd>テーブルの長さを返します。すなわち、要素数です。</dd> - <dt> - <h2 id="メソッド">メソッド</h2> - </dt> - <dt>{{jsxref("WebAssembly/Table/get","Table.prototype.get()")}}</dt> - <dd>アクセサ関数。インデックスから格納された要素を取得します。</dd> - <dt>{{jsxref("WebAssembly/Table/grow","Table.prototype.grow()")}}</dt> - <dd>指定した要素数で Table インスタンスを拡張します。</dd> - <dt>{{jsxref("WebAssembly/Table/set","Table.prototype.set()")}}</dt> - <dd>指定したインデックスに要素を格納します。</dd> -</dl> - -<h2 id="仕様">仕様</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様</th> - <th scope="col">策定状況</th> - <th scope="col">コメント</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('WebAssembly JS', '#webassemblytable-objects', 'Table')}}</td> - <td>{{Spec2('WebAssembly JS')}}</td> - <td>初回ドラフト定義</td> - </tr> - </tbody> -</table> - -<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2> - -<div> - - -<p>{{Compat("javascript.builtins.WebAssembly.Table.prototype")}}</p> -</div> - -<h2 id="関連情報">関連情報</h2> - -<ul> - <li>{{jsxref("WebAssembly.Table")}}</li> - <li><a href="/ja/docs/WebAssembly">WebAssembly</a> overview page</li> - <li><a href="/ja/docs/WebAssembly/Concepts">WebAssemblyのコンセプト</a></li> - <li><a href="/ja/docs/WebAssembly/Using_the_JavaScript_API">WebAssembly JavaScript API を使用する</a></li> -</ul> diff --git a/files/ja/web/javascript/reference/operators/comparison_operators/index.html b/files/ja/web/javascript/reference/operators/comparison_operators/index.html deleted file mode 100644 index 5010c8eb89..0000000000 --- a/files/ja/web/javascript/reference/operators/comparison_operators/index.html +++ /dev/null @@ -1,232 +0,0 @@ ---- -title: 比較演算子 -slug: Web/JavaScript/Reference/Operators/Comparison_Operators -tags: - - JavaScript - - Operator - - Reference - - 演算子 -translation_of: Web/JavaScript/Reference/Operators -translation_of_original: Web/JavaScript/Reference/Operators/Comparison_Operators ---- -<div>{{jsSidebar("Operators")}}</div> - -<p>JavaScript には、厳密な比較と型変換の比較の両方があります。厳密な比較 (例: <code>===</code>) は、オペランドが同じ型で、内容も一致している場合にのみ真になります。もっとよく使用される抽象的な比較 (例: <code>==</code>) は、比較する前にオペランドを同じ型に変換します。抽象的な関係比較 (例: <code><=</code>) では、比較前にまずオペランドがプリミティブ型に変換され、それから同じ型に変換されます。</p> - -<p>文字列は Unicode 値を使用した標準的な辞書順に基づいて比較されます。</p> - -<div>{{EmbedInteractiveExample("pages/js/expressions-equality.html")}}</div> - -<div> -<div>{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}</div> -</div> - -<div></div> - -<p class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</p> - -<p>比較の機能は以下のとおりです。</p> - -<ul> - <li>2 つの文字列が厳密に等しくなるのは、字の順序が等しく、長さが等しく、対応する位置の文字が等しいときです。</li> - <li>2 つの数字が厳密に等しくなるのは、数値的に等しいとき (数字の値が等しいとき) です。<a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/NaN" title="NaN">NaN</a> は、どんなものとも (Nan とさえも) 等しくなりません。プラスゼロとマイナスゼロは互いと等しくなります。</li> - <li>2 つの論理オペランドが厳密に等しくなるのは、どちらも <code>true</code> か、どちらも <code>false</code> のときです。</li> - <li>2 つの異なるオブジェクトは、厳密な比較でも抽象的な比較でも等しくなりません。</li> - <li>オブジェクト比較が等しくなるのは、オペランドが同じオブジェクトを参照しているときだけです。</li> - <li>Null と Undefined 型は、自分自身と厳密に等しく、また互いに抽象的に等しくなります。</li> -</ul> - -<h2 id="Equality_operators" name="Equality_operators">等価演算子</h2> - -<h3 id="Equality" name="Equality">等価 (==)</h3> - -<p>等価演算子は、2 つのオペランドが<strong>同じ型でないならば</strong>オペランドを変換して、それから厳密な比較を行います。<strong>両方のオペランドがオブジェクトならば</strong>、 JavaScript は内部参照を比較するので、オペランドがメモリ内の同じオブジェクトを参照するときに等しくなります。</p> - -<h4 id="Syntax" name="Syntax">構文</h4> - -<pre class="syntaxbox notranslate">x == y -</pre> - -<h4 id="Examples" name="Examples">例</h4> - -<pre class="brush: js notranslate">1 == 1 // true -'1' == 1 // true -1 == '1' // true -0 == false // true -0 == null // false -var object1 = {'key': 'value'}, object2 = {'key': 'value'}; -object1 == object2 // false -0 == undefined // false -null == undefined // true -</pre> - -<h3 id="Inequality" name="Inequality">不等価 (!=)</h3> - -<p>不等価演算子は、オペランド同士が等しくないならば真を返します。2 つのオペランドが<strong>同じ型でないならば</strong>、JavaScript は適切な型にオペランドを変換して比較しようとします。<strong>両方のオペランドがオブジェクトならば</strong>、JavaScript は内部参照を比較するので、オペランドがメモリ内の異なるオブジェクトを参照するときには等しくなりません。</p> - -<h4 id="Syntax_2" name="Syntax_2">構文</h4> - -<pre class="syntaxbox notranslate">x != y</pre> - -<h4 id="Examples_2" name="Examples_2">例</h4> - -<pre class="brush: js notranslate">1 != 2 // true -1 != '1' // false -1 != "1" // false -1 != true // false -0 != false // false -</pre> - -<h3 id="Identity" name="Identity">一致 / 厳密等価 (===)</h3> - -<p>厳密等価演算子は、<strong>型変換なしで</strong>オペランド同士が (上に示した通り) 厳密に等しければ真を返します。</p> - -<h4 id="Syntax_3" name="Syntax_3">構文</h4> - -<pre class="syntaxbox notranslate">x === y</pre> - -<h4 id="Examples_3" name="Examples_3">例</h4> - -<pre class="brush: js notranslate">3 === 3 // true -3 === '3' // false -var object1 = {'key': 'value'}, object2 = {'key': 'value'}; -object1 === object2 //false</pre> - -<h3 id="Nonidentity" name="Nonidentity">不一致 / 厳密不等価 (!==)</h3> - -<p>厳密不等価演算子は、<strong>オペランド同士が等しくないか、型が等しくない、あるいはその両方</strong>ならば真を返します。</p> - -<h4 id="Syntax_4" name="Syntax_4">構文</h4> - -<pre class="syntaxbox notranslate">x !== y</pre> - -<h4 id="Examples_4" name="Examples_4">例</h4> - -<pre class="brush: js notranslate">3 !== '3' // true -4 !== 3 // true -</pre> - -<h2 id="Relational_operators" name="Relational_operators">関係演算子</h2> - -<p>これらの演算子のそれぞれは、比較が行われる前に、そのオペランドをプリミティブに{{Glossary("Type_coercion", "型強制")}}します。両方とも文字列として終わる場合は、辞書順で比較され、そうでない場合は数値に変換されて比較されます。 <code>NaN</code> との比較は常に <code>false</code> を生み出します。</p> - -<h3 id="Greater_than_operator" name="Greater_than_operator">大なり演算子 (>)</h3> - -<p>大なり演算子は、左オペランドが右オペランドより大きければ、真を返します。</p> - -<h4 id="Syntax_5" name="Syntax_5">構文</h4> - -<pre class="syntaxbox notranslate">x > y</pre> - -<h4 id="Examples_5" name="Examples_5">例</h4> - -<pre class="brush: js notranslate">4 > 3 // true -</pre> - -<h3 id="Greater_than_or_equal_operator" name="Greater_than_or_equal_operator">大なりイコール演算子 (>=)</h3> - -<p>大なりイコール演算子は、左オペランドが右オペランド以上ならば、真を返します。</p> - -<h4 id="Syntax_6" name="Syntax_6">構文</h4> - -<pre class="syntaxbox notranslate"> x >= y</pre> - -<h4 id="Examples_6" name="Examples_6">例</h4> - -<pre class="brush: js notranslate">4 >= 3 // true -3 >= 3 // true -</pre> - -<h3 id="Less_than_operator" name="Less_than_operator">小なり演算子 (<)</h3> - -<p>小なり演算子は、左オペランドが右オペランドより小さければ、真を返します。</p> - -<h4 id="Syntax_7" name="Syntax_7">構文</h4> - -<pre class="syntaxbox notranslate"> x < y</pre> - -<h4 id="Examples_7" name="Examples_7">例</h4> - -<pre class="brush: js notranslate">3 < 4 // true -</pre> - -<h3 id="Less_than_or_equal_operator" name="Less_than_or_equal_operator">小なりイコール演算子 (<=)</h3> - -<p>小なりイコール演算子は、左オペランドが右オペランド以下ならば、真を返します。</p> - -<h4 id="Syntax_8" name="Syntax_8">構文</h4> - -<pre class="syntaxbox notranslate"> x <= y</pre> - -<h4 id="Examples_8" name="Examples_8">例</h4> - -<pre class="brush: js notranslate">3 <= 4 // true -3 <= 3 // true -</pre> - -<h2 id="Using_the_equality_operators" name="Using_the_equality_operators">等価演算子の使用</h2> - -<p>標準等価演算子 (<code>==</code> と <code>!=</code>) は 2 つのオペランドの比較に<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3">抽象的等価比較アルゴリズム</a>を使用します。オペランドの型が異なる場合は、比較を行う前にそれらを同じ型に変換しようとします。例えば <code>5 == '5'</code> という式では、比較を行う前に右オペランドの文字列を数値に変換します。</p> - -<p>厳密等価演算子 (<code>===</code> と <code>!==</code>) は<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6">厳密等価比較アルゴリズム</a>を使用して、オペランドの型が同一かどうかに関する比較も行います。オペランドの型が異なれば、例えば <code>5</code> と <code>'5'</code> の比較では、同一性比較 <code>5 !== '5'</code> は <code>true</code> と評価され、 <code>5 === '5'</code> のチェックは <code>false</code> 評価されます。</p> - -<p>厳密等価演算子を使うのは、オペランドが特定の型の特定の値でなければならない場合、言い換えればオペランドの正確な型が重要な場合です。それ以外では、2 つのオペランドが同じ型でなくても比較が可能になる、標準的な等価演算子を使えます。</p> - -<p>比較に型の変換が関わるとき (つまり厳密でない比較のとき)、 JavaScript は以下のように {{jsxref("String")}}, {{jsxref("Number")}}, {{jsxref("Boolean")}}, {{jsxref("Object")}} 型のオペランドを変換します。</p> - -<ul> - <li>数値と文字列を比較するとき、文字列は数値に変換されます。 JavaScript は文字列の数値リテラルを <code>Number</code> 型の値に変換しようとします。まず、文字列の数値リテラルから数学的な値を引き出します。次に、その値を最も近い <code>Number</code> 型に丸めます。</li> - <li>もしオペランドの片方が <code>Boolean</code> ならば、その Boolean オペランドが <code>true</code> の場合 1 に、<code>false</code> の場合は +0 に変換されます。</li> - <li>オブジェクトを数値または文字列と比較すると、 JavaScript はそのオブジェクトの既定値を返そうとします。演算子は、オブジェクトの <code>valueOf</code> や <code>toString</code> といったメソッドを用いて、プリミティブな値、 <code>String</code> か <code>Number</code> の値に変換しようとします。変換に失敗したら、ランタイムエラーが発生します。</li> - <li>オブジェクトがプリミティブ値に変換されるのは、比較対象がプリミティブ値であるときだけです。両方のオペランドがオブジェクトなら、オブジェクトとして比較され、両方が同じオブジェクトを参照するときだけ真となります。</li> -</ul> - -<div class="note"><strong>メモ:</strong> String オブジェクトはオブジェクト型であり、文字列型ではありません! String オブジェクトはほとんど使わないので、次の結果に驚くかもしれません。</div> - -<pre class="brush:js notranslate">// 両方のオペランドが文字列型 (すなわちプリミティブな文字列) なので、true -'foo' === 'foo' - -var a = new String('foo'); -var b = new String('foo'); - -// a と b はオブジェクト型で、異なるオブジェクトを参照しているので、false -a == b - -// a と b はオブジェクト型で、異なるオブジェクトを参照しているので、false -a === b - -// a と 'foo' は異なる型で、比較前にオブジェクト (a) は -// 文字列 'foo' に変換されるので、真 -a == 'foo'</pre> - -<h2 id="Specifications" name="Specifications">仕様書</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様書</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ESDraft', '#sec-equality-operators', 'Equality Operators')}}</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-relational-operators', 'Relational Operators')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> - -<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> - -<p>{{Compat("javascript.operators.comparison")}}</p> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li>{{jsxref("Object.is()")}}</li> - <li>{{jsxref("Math.sign()")}}</li> - <li><a href="/ja/docs/Web/JavaScript/Equality_comparisons_and_sameness">等価性の比較とその使いどころ</a></li> -</ul> diff --git a/files/ja/web/javascript/reference/operators/logical_operators/index.html b/files/ja/web/javascript/reference/operators/logical_operators/index.html deleted file mode 100644 index 8b43c3de26..0000000000 --- a/files/ja/web/javascript/reference/operators/logical_operators/index.html +++ /dev/null @@ -1,295 +0,0 @@ ---- -title: 論理演算子 -slug: Web/JavaScript/Reference/Operators/Logical_Operators -tags: - - JavaScript - - Operator -translation_of: Web/JavaScript/Reference/Operators -translation_of_original: Web/JavaScript/Reference/Operators/Logical_Operators ---- -<div>{{jsSidebar("Operators")}}</div> - -<h2 id=".E6.A6.82.E8.A6.81" name=".E6.A6.82.E8.A6.81">概要</h2> - -<p>{{ 原語併記("論理演算子", "Logical operators") }} は、基本的に真偽(論理)値とともに用いられ真偽値を返します。しかし、<code>&&</code> および <code>||</code> 演算子は真偽値ではない値も使うことができるため、その場合は、真偽値ではない値を返すことがあります。その場合の考え方は以下の「説明」の欄の記載の通りとなります。</p> - -<h2 id="Description" name="Description">説明</h2> - -<p>論理演算子を以下の表で説明します。:</p> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th>演算子</th> - <th>使用法</th> - <th>説明</th> - </tr> - <tr> - <td>論理 AND(<code>&&</code>)</td> - <td><code><em>expr1</em> && <em>expr2</em></code></td> - <td><code>expr1</code> を false と見ることができる場合は、<code>expr1</code> を返します。そうでない場合は、<code>expr2</code> を返します。したがって、真偽値と共に使われた場合、 演算対象の両方が true ならば、<code>&&</code> は、true を返し、そうでなければ、false を返します。</td> - </tr> - <tr> - <td>論理 OR (<code>||</code>)</td> - <td><code><em>expr1</em> || <em>expr2</em></code></td> - <td><code>expr1</code> を true と見ることができる場合は、<code>expr1</code> を返します。そうでない場合は、<code>expr2</code> を返します。したがって、真偽値と共に使われた場合、 演算対象のどちらかが true ならば、<code>||</code> は、true を返し、両方とも false の場合は、false を返します。</td> - </tr> - <tr> - <td>論理 NOT (<code>!</code>)</td> - <td><code>!<em>expr</em></code></td> - <td>単一の演算対象が true と見ることができる場合は、false を返します。そうでない場合は、true を返します。</td> - </tr> - </tbody> -</table> - -<p><code>true</code> に変換できる値は、いわゆる {{Glossary("truthy")}} です。<code>false</code> に変換できる値は、いわゆる {{Glossary("falsy")}} です。</p> - -<p><code>false</code> と見ることができる式の例は、null、0、空文字列 ("")、あるいは、<code>undefined</code> と評価されるものです。</p> - -<p><code>&&</code> と <code>||</code> 演算子が真偽値ではない値である演算対象とともに用いることができても、それらは、真偽演算子と考えることができます。なぜなら、それらの戻り値は、常に、真偽値と見ることができるからです。</p> - -<h3 id=".E3.82.B7.E3.83.A7.E3.83.BC.E3.83.88.E3.82.B5.E3.83.BC.E3.82.AD.E3.83.83.E3.83.88.E8.A9.95.E4.BE.A1" name=".E3.82.B7.E3.83.A7.E3.83.BC.E3.83.88.E3.82.B5.E3.83.BC.E3.82.AD.E3.83.83.E3.83.88.E8.A9.95.E4.BE.A1">ショートサーキット評価</h3> - -<p>論理演算子は左から右へ評価されるため、論理演算子で左辺を評価した時点で論理式の結果が確定した場合には右辺の評価を行わないことを、ショートサーキット評価といいます。例えば、A && Bという論理式があった場合、Aがfalseなら、その時点で式全体の結果はfalseで確定するため、Bがどうであるかについてはチェックしません。:</p> - -<ul> - <li><code>false && (<em>anything</em>)</code> をショートサーキット評価すると、false になります。</li> - <li><code>true || (<em>anything</em>)</code> をショートサーキット評価すると、true になります。</li> -</ul> - -<p> 上記の式の anything の部分は評価されません。また、<strong>上記の式の anything の部分は (括弧で示しているとおり) ひとつの論理式ですので注意してください。</strong></p> - -<p>例えば、以下の 2 つの関数は等価です。</p> - -<pre class="brush: js">function shortCircuitEvaluation() { - doSomething() || doSomethingElse() -} - -function equivalentEvaluation() { - var flag = doSomething(); - if (!flag) { - doSomethingElse(); - } -} -</pre> - -<p>しかし、以下の式は等価ではありません。これは<a href="/ja/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">演算子の優先順位</a>のためであり、右側の演算子をひとつの式にする (必要に応じて括弧でグループ化する) 必要性の重要度を高めています。</p> - -<pre class="brush: js">false && true || true // true を返す -false && (true || true) // false を返す</pre> - -<h3 id=".E8.AB.96.E7.90.86_AND_.28&&.29" name=".E8.AB.96.E7.90.86_AND_.28&&.29">論理 AND (<code>&&</code>)</h3> - -<p>以下のコードは、<code>&&</code> (論理 AND) 演算子の例を示しています。</p> - -<pre class="brush: js">a1 = true && true // t && t true を返します。 -a2 = true && false // t && f false を返します。 -a3 = false && true // f && t false を返します。 -a4 = false && (3 == 4) // f && f false を返します。 -a5 = "Cat" && "Dog" // t && t "Dog" を返します。 -a6 = false && "Cat" // f && t false を返します。 -a7 = "Cat" && false // t && f false を返します。 -</pre> - -<h3 id=".E8.AB.96.E7.90.86_OR_.28||.29" name=".E8.AB.96.E7.90.86_OR_.28||.29">論理 OR (<code>||</code>)</h3> - -<p>以下のコードは、<code>||</code> (論理 OR) 演算子の例を示しています。</p> - -<pre class="brush: js">o1 = true || true // t || t true を返します。 -o2 = false || true // f || t true を返します。 -o3 = true || false // t || f true を返します。 -o4 = false || (3 == 4) // f || f false を返します。 -o5 = "Cat" || "Dog" // t || t "Cat" を返します。 -o6 = false || "Cat" // f || t "Cat" を返します。 -o7 = "Cat" || false // t || f "Cat" を返します。 -</pre> - -<h3 id=".E8.AB.96.E7.90.86_NOT_.28.21.29" name=".E8.AB.96.E7.90.86_NOT_.28.21.29">論理 NOT (<code>!</code>)</h3> - -<p>以下のコードは、<code>!</code> (論理 NOT) 演算子の例を示しています。</p> - -<pre class="brush: js">n1 = !true // !t false を返します。 -n2 = !false // !f true を返します。 -n3 = !"Cat" // !t false を返します。 -</pre> - -<h3 id="Conversion_rules" name="Conversion_rules">変換規則</h3> - -<h4 id="Converting_AND_to_OR" name="Converting_AND_to_OR">AND から OR への変換</h4> - -<p>Boolean について以下の演算を行います:</p> - -<pre class="brush: js">bCondition1 && bCondition2</pre> - -<p>これは以下の演算と等価です:</p> - -<pre class="brush: js">!(!bCondition1 || !bCondition2)</pre> - -<h4 id="Converting_OR_to_AND" name="Converting_OR_to_AND">OR から AND への変換</h4> - -<p>Boolean について以下の演算を行います:</p> - -<pre class="brush: js">bCondition1 || bCondition2</pre> - -<p>これは以下の演算と等価です:</p> - -<pre class="brush: js">!(!bCondition1 && !bCondition2)</pre> - -<h4 id="Converting_between_NOTs" name="Converting_between_NOTs">NOT 間の変換</h4> - -<p>Boolean について以下の演算を行います:</p> - -<pre class="brush: js">!!bCondition</pre> - -<p>これは以下の演算と等価です:</p> - -<pre class="brush: js">bCondition</pre> - -<h3 id="Removing_nested_parentheses" name="Removing_nested_parentheses">入れ子の括弧を削除する</h3> - -<p>論理演算子は左から右へ評価されるため、複雑な式の中にある括弧をいくつかの規則に従って削除することができます。</p> - -<h4 id="Removing_nested_AND" name="Removing_nested_AND">入れ子の AND を削除する</h4> - -<p>Boolean について以下の複雑な演算を行います:</p> - -<pre class="brush: js">bCondition1 || (bCondition2 && bCondition3)</pre> - -<p>これは以下の演算と等価です:</p> - -<pre class="brush: js">bCondition1 || bCondition2 && bCondition3</pre> - -<h4 id="Removing_nested_OR" name="Removing_nested_OR">入れ子の OR を削除する</h4> - -<p>Boolean について以下の複雑な演算を行います:</p> - -<pre class="brush: js">bCondition1 && (bCondition2 || bCondition3)</pre> - -<p>これは以下の演算と等価です:</p> - -<pre class="brush: js">!(!bCondition1 || !bCondition2 && !bCondition3)</pre> - -<h2 id="Specifications" name="Specifications">仕様</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">仕様書</th> - <th scope="col">策定状況</th> - <th scope="col">コメント</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>最初期の定義</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-11.11')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td>仕様書内のいくつかのセクションで定義: <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.9">Logical NOT Operator</a>, <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.11">Binary Logical Operators</a></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-binary-logical-operators')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>仕様書内のいくつかのセクションで定義: <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-logical-not-operator">Logical NOT Operator</a>, <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-binary-logical-operators">Binary Logical Operators</a></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-binary-logical-operators')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td>仕様書内のいくつかのセクションで定義: <a href="http://tc39.github.io/ecma262/#sec-logical-not-operator">Logical NOT Operator</a>, <a href="http://tc39.github.io/ecma262/#sec-binary-logical-operators">Binary Logical Operators</a></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザ実装状況</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>機能</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>論理 AND (<code>&&</code>)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td>論理 OR (<code>||</code>)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td>論理 NOT (<code>!</code>)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>機能</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>論理 AND (<code>&&</code>)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td>論理 OR (<code>||</code>)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td>論理 NOT (<code>!</code>)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li><a href="/ja/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators">ビット演算子</a></li> - <li><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a></li> -</ul> diff --git a/files/ja/web/javascript/reference/operators/special/index.html b/files/ja/web/javascript/reference/operators/special/index.html deleted file mode 100644 index cb220a008d..0000000000 --- a/files/ja/web/javascript/reference/operators/special/index.html +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Special -slug: Web/JavaScript/Reference/Operators/Special ---- -This page was auto-generated because a user created a sub-page to this page. diff --git a/files/ja/web/javascript/reference/operators/special_operators/index.html b/files/ja/web/javascript/reference/operators/special_operators/index.html deleted file mode 100644 index febf3ac3d6..0000000000 --- a/files/ja/web/javascript/reference/operators/special_operators/index.html +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Special Operators -slug: Web/JavaScript/Reference/Operators/Special_Operators ---- -This page was auto-generated because a user created a sub-page to this page. diff --git a/files/ja/web/javascript/reference/reserved_words/index.html b/files/ja/web/javascript/reference/reserved_words/index.html deleted file mode 100644 index fabc275890..0000000000 --- a/files/ja/web/javascript/reference/reserved_words/index.html +++ /dev/null @@ -1,89 +0,0 @@ ---- -title: 予約語 -slug: Web/JavaScript/Reference/Reserved_Words -tags: - - JavaScript -translation_of: Web/JavaScript/Reference/Lexical_grammar#Keywords -translation_of_original: Web/JavaScript/Reference/Reserved_Words ---- -<p>以下は予約語であり、変数、関数、メソッド、あるいはオブジェクトの識別子として用いることはできません。以下は <a href="/ja/docs/ECMAScript">ECMAScript</a> の仕様で既存のキーワードとして予約されているものです。</p> - -<div class="threecolumns"> -<ul> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/break" title="JavaScript/Reference/Statements/break">break</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/switch" title="JavaScript/Reference/Statements/switch">case</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/try...catch" title="JavaScript/Reference/Statements/try...catch">catch</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/continue" title="JavaScript/Reference/Statements/continue">continue</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/debugger" title="JavaScript/Reference/Statements/debugger">debugger</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/switch" title="JavaScript/Reference/Statements/switch">default</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Operators/delete" title="JavaScript/Reference/Operators/delete">delete</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/do...while" title="JavaScript/Reference/Statements/do...while">do</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/if...else" title="JavaScript/Reference/Statements/if...else">else</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/try...catch" title="JavaScript/Reference/Statements/try...catch">finally</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/for" title="JavaScript/Reference/Statements/for">for</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/function" title="JavaScript/Reference/Statements/function">function</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/if...else" title="JavaScript/Reference/Statements/if...else">if</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/for...in" title="JavaScript/Reference/Statements/for...in">in</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Operators/instanceof" title="JavaScript/Reference/Operators/instanceof">instanceof</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Operators/new" title="JavaScript/Reference/Operators/new">new</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/return" title="JavaScript/Reference/Statements/return">return</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/switch" title="JavaScript/Reference/Statements/switch">switch</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Operators/this" title="JavaScript/Reference/Operators/this">this</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/throw" title="JavaScript/Reference/Statements/throw">throw</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/try...catch" title="JavaScript/Reference/Statements/try...catch">try</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Operators/typeof" title="JavaScript/Reference/Operators/typeof">typeof</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/var" title="JavaScript/Reference/Statements/var">var</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Operators/void" title="JavaScript/Reference/Operators/void">void</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/while" title="JavaScript/Reference/Statements/while">while</a></code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/with" title="JavaScript/Reference/Statements/with">with</a></code></li> -</ul> -</div> - -<h2 id="Words_reserved_for_possible_future_use" name="Words_reserved_for_possible_future_use">将来の使用を見越した予約語</h2> - -<p>以下は ECMAScript の仕様で将来のキーワードとして予約されているものです。現在は特別な機能を持っていませんが、将来機能を持つときのために、識別子として使用できません。このキーワードは、厳格モード、非厳格モードの両方で使用できません。</p> - -<div class="note"><strong>注記:</strong> Firefox 5 (JavaScript 1.8.6) より以前では、これらのキーワードは厳格モードでないときには使用できました。この ECMAScript 違反は Firefox 5 で修正されました。</div> - -<div class="threecolumns"> -<ul> - <li><code>class</code></li> - <li><code>enum</code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/export" title="JavaScript/Reference/Statements/export">export</a></code></li> - <li><code>extends</code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/import" title="JavaScript/Reference/Statements/import">import</a></code></li> - <li><code>super</code></li> -</ul> -</div> - -<p>以下は <a href="/ja/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode" title="JavaScript/Strict mode">厳格モードのコード</a> として実行されたときに 、ECMAScript の仕様で将来のキーワードとして 予約されているものです。ただし、JavaScript 1.7 以上では <code>let</code> と <code>yield</code> は伝統的な Mozilla 特有の機能を持っています。</p> - -<div class="threecolumns"> -<ul> - <li><code>implements</code></li> - <li><code>interface</code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/let" title="JavaScript/Reference/Statements/let">let</a></code></li> - <li><code>package</code></li> - <li><code>private</code></li> - <li><code>protected</code></li> - <li><code>public</code></li> - <li><code>static</code></li> - <li><code><a href="/ja/docs/JavaScript/Reference/Statements/yield" title="JavaScript/Reference/Statements/yield">yield</a></code></li> -</ul> -</div> - -<p><code><a href="/ja/docs/JavaScript/Reference/Statements/const" title="JavaScript/Reference/Statements/const">const</a></code> は ECMAScript の仕様によって将来のキーワードとして予約されていますが、Mozilla やほとんどの他のブラウザが非標準の拡張として実装していることに注意してください。さらに、 <a href="/ja/docs/JavaScript/Reference/Statements/export" title="JavaScript/Reference/Statements/export">export</a> と <a href="/ja/docs/JavaScript/Reference/Statements/import" title="JavaScript/Reference/Statements/import">import</a> はかつて Mozilla で実装されていましたが、現在では予約語となっています。</p> - -<p>加えて、 <code>null</code> 、 <code>true</code> 、 <code>false</code> リテラルは ECMAScript の仕様で予約されています。</p> - -<h2 id="Reserved_word_usage" name="Reserved_word_usage">予約語の利用</h2> - -<p>実際に、予約語は識別子のみに適用されます。<span class="comment-copy"><a href="http://es5.github.com/#A.1" rel="nofollow">es5.github.com/#A.1</a> の記述にあるように、これらは全て予約語を排除しない識別名です。</span></p> - -<p><span class="comment-copy"><code>a.import</code></span><br> - <span class="comment-copy"><code>a["import"]</code></span><br> - <span class="comment-copy"><code>a = { import: "test" }</code>.</span></p> - -<p><span class="comment-copy">反対に、以下は識別子であるので違反です。識別子は関数宣言や関数式に使用されます。</span></p> - -<p><span class="comment-copy"><code>function import() {}</code></span></p> diff --git a/files/ja/web/javascript/reference/statements/yield/index.html b/files/ja/web/javascript/reference/statements/yield/index.html deleted file mode 100644 index 69be44e8d9..0000000000 --- a/files/ja/web/javascript/reference/statements/yield/index.html +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: yield -slug: Web/JavaScript/Reference/Statements/yield -translation_of: Web/JavaScript/Reference/Operators/yield -translation_of_original: Web/JavaScript/Reference/Statements/yield ---- -<p>『 <a href="/ja/docs/JavaScript/New_in_JavaScript/1.7">JavaScript 1.7 の新機能</a>』、『<a href="/ja/docs/JavaScript/Guide/Iterators_and_Generators">イテレータとジェネレータ</a>』 を参照して下さい。</p> |