翻訳 4章まで: "JavaScript" In Wikipedia, The Free Encyclopedia

 

  • この記事は、コンピュータサイエンスに関する技術および英語についての正確な知識のない翻訳者が個人的な勉強を目的として、ほぼ全てを意訳によって翻訳したために、極めて多くの誤訳が含まれていると想定される決して質が高いとは言えない文章を公開しているものです。ここに掲載されている情報を使用したことによる、読者の方または第三者に生じる損害および損失について、翻訳者は一切の責任を負いません。正しい情報が必要な場合は原文を参照してください。

 

JavaScript (/ˈdʒɑːvəˌskrɪpt/),[6] often abbreviated as JS, is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm.

JavaScriptはしばしばJSと略され、高水準インタプリタ形式のプログラミング言語だ。動的、弱い型付け、プロトタイプベース、マルチ・パラダイムといった特徴もある。

Alongside HTML and CSS, JavaScript is one of the three core technologies of the World Wide Web.[7] JavaScript enables interactive web pages and thus is an essential part of web applications. The vast majority of websites use it,[8] and all major web browsers have a dedicated JavaScript engine to execute it.

HTMLやCSSと一緒に、JavaScriptワールドワイドウェブの3つの中心的な技術の一つだ。JavaScriptインタラクティブなウェブページを可能にしてウェブアプリケーションの極めて重要な一部だ。ウェブサイトの大半で使われていて、主要なウェブブラウザーではJavaScript専用エンジンを使って処理する。

As a multi-paradigm language, JavaScript supports event-driven, functional, and imperative (including object-oriented and prototype-based) programming styles. It has an API for working with text, arrays, dates, regular expressions, and basic manipulation of the DOM, but the language itself does not include any I/O, such as networking, storage, or graphics facilities, relying for these upon the host environment in which it is embedded.

マルチ・パラダイム言語として、JavaScriptはイベント駆動型、関数型、命令型(オブジェクト指向とプロトタイプベースを含む)のプログラミングパラダイムだ。テキスト、配列、データ、正規表現、DOMの基本的操作のためのAPIがあるが、ネットワーク、ストレージ、グラフィックス機能といった入出力機能は一切なく、組み込まれたホスト環境に依存している。

Initially only implemented client-side in web browsers, JavaScript engines are now embedded in many other types of host software, including server-side in web servers and databases, and in non-web programs such as word processors and PDF software, and in runtime environments that make JavaScript available for writing mobile and desktop applications, including desktop widgets.
JavaScriptエンジンは、始めのうちはウェブブラウザーのクライアント側にのみ実装されていたが、今ではウェブサーバー、データベース、ワードプロセッサーやPDFソフトウェアのような非ウェブプログラム、JavaScripでデスクトップウィジェットを含むモバイルやデスクトップアプリケーションを記述できるようにする実行環境といったサーバー側を含む多くの他のホストソフトウェアに組み込まれている。

Although there are strong outward similarities between JavaScript and Java, including language name, syntax, and respective standard libraries, the two languages are distinct and differ greatly in design; JavaScript was influenced by programming languages such as Self and Scheme.[9]

JavaScripとJavaの間には言語の名前、文法、個々の標準ライブラリといったように表面上は強い類似点があるが、これらの言語は設計の点で全く別でかなり異なっている。JavaScripはSelfやSchemeといったようなプログラミング言語の影響を受けている。

1 History 歴史 ※割愛

1.1 Beginnings at Netscape

1.2 Server-side JavaScript

1.3 Adoption by Microsoft

1.4 Standardization

1.5 Later developments

2 Trademark 商標

"JavaScript" is a trademark of Oracle Corporation in the United States.[28] It is used under license for technology invented and implemented by Netscape Communications and current entities such as the Mozilla Foundation.[29]

「JavaScrip」は米国オラクルの商標である。Netscape CommunicationsMozilla Foundationのような現在のエンティティによって開発・実装された技術の許可を受けた。

3 Vanilla JavaScript

The terms Vanilla JavaScript and Vanilla JS refer to JavaScript not extended by any frameworks or additional libraries. Scripts written in Vanilla JS are plain JavaScript code.[30][31]

Vanilla JavaScript と Vanilla JSという言葉はフレームワークや追加のライブラリで拡張されていないJavaScripを指している。Vanilla JSで書かれたスクリプトは普通のJavaScripコードである。

4 Features 特徴

4.1 Universal support 普遍的なサポート

All modern Web browsers support JavaScript with built-in interpreters.

全てのモダンなブラウザーインタープリターを備えていてJavaScripをサポートしている。

4.2 Imperative and structured 命令と構造

JavaScript supports much of the structured programming syntax from C (e.g., if statements, while loops, switch statements, do while loops, etc.). One partial exception is scoping: JavaScript originally had only function scoping with var. ECMAScript 2015 added keywords let and const for block scoping, meaning JavaScript now has both function and block scoping. Like C, JavaScript makes a distinction between expressions and statements. One syntactic difference from C is automatic semicolon insertion, which allows the semicolons that would normally terminate statements to be omitted.[32]

JavaScripはCを由来とする構造化プログラミングの大半(例えば、if文、while文、swith文、do-while文など)をサポートする。一部の例外はスコープだ。JavaScripははじめはvarによる関数スコープのみであった。ECMAScript 2015 でブロックスコープのためのletとconstが追加されて、JavaScripは今では関数とブロックの両方のスコープがある。Cのように、JavaScripでは式と文を区別する。Cとのシンタックスの違いの一つは自動的にセミコロンが挿入されることで、それにより文の最後に置かれるセミコロンを省略することができる。

4.3 Dynamic 動的

Typing

As with most scripting languages, JavaScript is dynamically typed; a type is associated with each value, rather than just with each expression. For example, a variable that is at one time bound to a number may later be re-bound to a string.[33] JavaScript supports various ways to test the type of an object, including duck typing.[34]

ほとんどのスクリプト言語のように、JavaScripは動的型付けだ。型は単にそれぞれの式よりも、それぞれの値に関連付けられる。例えば、ある時点で数と結びついている変数はそのあと文字列に結び付けられなおされるかもしれない。JavaScripはダックタイピングを含むオブジェクトの型をテストする様々な方法をサポートしている。

Run-time evaluation 実行時評価

JavaScript includes an eval function that can execute statements provided as strings at run-time.

JavaScripには実行時に文字列として提供される文を実行できる評価関数がある。

4.4 Prototype-based (object-oriented) プロトタイプベース(オブジェクト指向

JavaScript is almost entirely object-based. In JavaScript, an object is an associative array, augmented with a prototype (see below); each string key provides the name for an object property, and there are two syntactical ways to specify such a name: dot notation (obj.x = 10) and bracket notation (obj['x'] = 10). A property may be added, rebound, or deleted at run-time. Most properties of an object (and any property that belongs to an object's prototype inheritance chain) can be enumerated using a for...in loop.

JavaScripはほとんど完全にオブジェクト指向だ。JavaScripでは、オブジェクトのプロパティは(以下で見るように)プロトタイプで増加する連想配列である。つまり、それぞれのキーはオブジェクトの名前を指し、そのような名前を指定するには二つの文法的方法がある。ドット表記(obj.x = 10)と角括弧(obj['x']=10)である。プロパティは実行時に追加、リバインド、削除できる。オブジェクト(とオブジェクトのプロトタイプチェーンに属するプロパティ)のほとんどのプロパティはfor...in loopを使って数え上げることができる。

JavaScript has a small number of built-in objects, including Function and Date.

JavaScripには関数と日付を含むビルトインオブジェクトが少ない。

Prototypes

JavaScript uses prototypes where many other object-oriented languages use classes for inheritance.[35] It is possible to simulate many class-based features with prototypes in JavaScript.[36]

JavaScripにはほかの多くのオブジェクト指向言語が継承のために使うクラスに相当するプロトタイプがあり、プロトタイプを使ってクラスベースの多くの特徴をシミュレーションできる。

Functions as object constructors オブジェクトのコンストラクタとしての関数

Functions double as object constructors, along with their typical role. Prefixing a function call with new will create an instance of a prototype, inheriting properties and methods from the constructor (including properties from the Object prototype).[37] ECMAScript 5 offers the Object.create method, allowing explicit creation of an instance without automatically inheriting from the Object prototype (older environments can assign the prototype to null).[38] The constructor's prototype property determines the object used for the new object's internal prototype. New methods can be added by modifying the prototype of the function used as a constructor. JavaScript's built-in constructors, such as Array or Object, also have prototypes that can be modified. While it is possible to modify the Object prototype, it is generally considered bad practice because most objects in JavaScript will inherit methods and properties from the Object prototype, and they may not expect the prototype to be modified.[39]

関数は本来の役割に加えて、オブジェクトのコンストラクタとしても働く。newを関数の前に付けると(オブジェクトのプロトタイプからのプロパティを含む)コンストラクタからのプロパティとメソッドを継承した、プロトタイプのインスタンスを生成する。 ECMAScript 5では、オブジェクトのプロトタイプからの自動的な継承をせずにインスタンスを明示的に作れる、オブジェクト生成メソッドが提供される(より古い環境ではプロトタイプをnullに割り当てられる)。コンストラクタのプロトタイププロパティは新しいオブジェクトの内部プロトタイプのために使われるオブジェクトを決定する。JavaScripのArrayやObjectといった内蔵コンストラクタは修正されることができるプロトタイプを備えている。オブジェクトのプロトタイプを修正することができる一方で、一般的にはJavaScripのほとんどのオブジェクトはオブジェクトのプロトタイプからメソッドとプロパティを継承するだろうし、それらは修正されたプロトタイプであることを要求しないので悪い習慣だと考えられる。

Functions as methods メソッドとしての関数

Unlike many object-oriented languages, there is no distinction between a function definition and a method definition. Rather, the distinction occurs during function calling; when a function is called as a method of an object, the function's local this keyword is bound to that object for that invocation.

多くのオブジェクト指向言語と違って、関数の定義とメソッドの定義の間区別はない。むしろ、違いは関数の呼び出しにある。オブジェクトのメソッドとして関数が呼ばれると、関数のローカルthisキーワードはそのまじないのためのオブジェクトと結び付けられる。

4.5 Functional

A function is first-class; a function is considered to be an object. As such, a function may have properties and methods, such as .call() and .bind().[40] A nested function is a function defined within another function. It is created each time the outer function is invoked. In addition, each nested function forms a lexical closure: The lexical scope of the outer function (including any constant, local variable, or argument value) becomes part of the internal state of each inner function object, even after execution of the outer function concludes.[41] JavaScript also supports anonymous functions.

関数は第一級クラスだ。関数はオブジェクトとして考えられる。そのようにして、関数は、プロパティと.call(9や.bind()のようなメソッドを持つかもしれない。ネストされた関数はとは他の関数で定義された関数である。他の関数が呼び出されるたびに作成される。加えて、それぞれのネストされた関数は辞書的なクロージャを形成する。他の関数(全ての定数、ローカル変数、引数を含む)の辞書的範囲は外の関数の終わりの実行後ですら、それぞれの内部関数のオブジェクトの内部状態の一部になる。JavaScripでは無名関数をサポートする。

4.6 Delegative 委譲

JavaScript supports implicit and explicit delegation.

JavaScripは暗示的/明示的委譲をサポートする。

Functions as roles (Traits and Mixins) 役割としての関数

JavaScript natively supports various function-based implementations of Role[42] patterns like Traits[43][44] and Mixins.[45] Such a function defines additional behavior by at least one method bound to the this keyword within its function body. A Role then has to be delegated explicitly via call or apply to objects that need to feature additional behavior that is not shared via the prototype chain.

JavaScripは元々TraitとMixinのようなRoleパターンの様々な関数ベースの実装をサポートする。そのような関数は関数のボディーでthisキーワードに結び付けられた少なくとも一つの関数によって追加できに振る舞いを定義する。Roleはそれからプロトタイプチェーンによって共有されない追加の振る舞いをフューチャーする必要のないオブジェクトを読んだり適用することで明示的に委譲されなければならない。

Object composition and inheritance オブジェクトの集約と継承

Whereas explicit function-based delegation does cover composition in JavaScript, implicit delegation already happens every time the prototype chain is walked in order to, e.g., find a method that might be related to but is not directly owned by an object. Once the method is found it gets called within this object's context. Thus inheritance in JavaScript is covered by a delegation automatism that is bound to the prototype property of constructor functions.

JavaScripでは明示的な関数ベースの委譲が集約をカバーしている一方で、暗示的な委譲はすでにプロトタイプチェーンが例えば、関連しているがオブジェクトによって直接所有されていないメソッドを見つけるためにプロパティチェーンが張られるといつも発生する。メソッドが見つかるとオブジェクトのコンテクストないで呼ばれる。このようにJavaScripでは継承はコンストラクタ関数の適切なプロパティに結びついた委譲自動でカバーされる。

4.7 Miscellaneous 多様性

Run-time environment 実行環境

JavaScript typically relies on a run-time environment (e.g., a Web browser) to provide objects and methods by which scripts can interact with the environment (e.g., a webpage DOM). It also relies on the run-time environment to provide the ability to include/import scripts (e.g., HTML <script> elements). This is not a language feature per se, but it is common in most JavaScript implementations.

JavaScripは元々スクリプトと環境と相互に作用する(例えば、ウェブページのDOM)ことによってオブジェクトやメソッドを提供するために実行環境(例えば、ウェブブラウザー)に依存する。また、スクリプト(例えば、HTMLの<script>element)を入出力する能力を提供するために実行環境に依存する。これはそれ自体は言語の特徴ではないが、ほとんどJavaScrip実装では共通だ。
JavaScript processes messages from a queue one at a time. Upon loading a new message, JavaScript calls a function associated with that message, which creates a call stack frame (the function's arguments and local variables). The call stack shrinks and grows based on the function's needs. Upon function completion, when the stack is empty, JavaScript proceeds to the next message in the queue. This is called the event loop, described as "run to completion" because each message is fully processed before the next message is considered. However, the language's concurrency model describes the event loop as non-blocking: program input/output is performed using events and callback functions. This means, for instance, that JavaScript can process a mouse click while waiting for a database query to return information.[46]

JavaScriptはキューからメッセージを1つずつ処理する。新しいメッセージをロードしている時、JavaScripはコールスタックフレーム(関数の引数とローカル変数)を生成する、メッセージに関する関数を呼び出す。コールスタックは関数の要求に応じて小さくなったり大きくなったりする。関数が終了するとき、つまり、スタックが空になったとき、JavaScripはキューのなかの次のメッセージを処理する。これはイベントループとよばれ、次のメッセージが見られる前にそれぞれのメッセージを完全に処理するために、「終了まで実行する」といわれる。しかしながら、言語の同時実行モデルはイベントループを非ブロッキング、つまり、プログラムのioがイベントとコールバック関数を使うことで行われることとして説明する。実際にはこれはJavaScripが情報を返すためにデータベースクエリーを待っている間にマウスクリックを処理することができることを意味する。

Variadic functions 可変長引数関数

An indefinite number of parameters can be passed to a function. The function can access them through formal parameters and also through the local arguments object. Variadic functions can also be created by using the bind method.

不定の引数を関数に渡すことができる。関数は仮パラメータまたはローカルargumentオブジェクトと通じてそれらにアクセスできる。可変長引数関数はbindメソッドを使うことで作ることもできる。

Array and object literals

Like many scripting languages, arrays and objects (associative arrays in other languages) can each be created with a succinct shortcut syntax. In fact, these literals form the basis of the JSON data format.

多くのスクリプト言語のように、配列とオブジェクト(ほかの言語における連想配列)はそれぞれ簡単なショートカットシンタックスで作ることができる。実際、これらのリテラルJSONのデータフォーマットの基礎をつくる。

Regular expressions 正規表現

JavaScript also supports regular expressions in a manner similar to Perl, which provide a concise and powerful syntax for text manipulation that is more sophisticated than the built-in string functions.[47]

Javascriptはまた正規表現をstring関数に内蔵されているよりも洗練されたテキスト操作のための完結で強力な文法を提供するPerlに似た方法でサポートする。

4.8 Vendor-specific extensions ベンダー固有の拡張

JavaScript is officially managed by Mozilla Foundation, and new language features are added periodically. However, only some JavaScript engines support these new features:

JavaScripはMozilla Foundationによって公式に管理され、新しい言語の特徴は定期的に追加される。しかしながら、いくつかのJavaScripエンジンだけが次の特徴をサポートする。

  • property getter and setter functions (supported by WebKit, Gecko, Opera,[48] ActionScript, and Rhino)[49]
  • conditional catch clauses
  • iterator protocol (adopted from Python)
  • shallow generators-coroutines (adopted from Python)
  • array comprehensions and generator expressions (adopted from Python)
  • proper block scope via the let keyword
  • array and object destructuring (limited form of pattern matching)
  • concise function expressions (function(args) expr)
  • ECMAScript for XML (E4X), an extension that adds native XML support to ECMAScript (unsupported in Firefox since version 21[50])