DOM interfaces are defined outside of JavaScript, because the DOM can be manipulated in multiple languages (there was once a time when VBScript and Tcl could be used in browsers besides JavaScript), that's why the W3C's DOM specifications are language-agnostic, the DOM doesn't inherently have anything to do with JavaScript.
In cross-platform / cross-language APIs, interfaces are defined in a language like IDL (Interface Description Language), here's the IDL that defines EventTarget
(as used by Webkit): https://github.com/adobe/webkit/blob/master/Source/WebCore/dom/EventTarget.idl
JavaScript itself has no concept of interfaces (the same concept as C#/Java interface
) as it is a prototype language, it uses Duck-typing in lieu of interfaces with static typing,
JavaScript "classes" are a new feature in ECMAScript 6 (the next major revision of the specification JavaScript is based on), however it can be considered syntactic sugar to simplify the creation of instances from the same prototype constructor and they too are distinct from this interface concept.
In summary:
API interface
- A specification for a platform or library to implement
- Defined in IDL or an IDL-like language (e.g. MIDL)
- Language-independent / Language-agnostic
Language interface
- Is a feature of a language (
interface
in Java or C#, __interface
in Microsoft Visual C++, protocol
in Swift and ObjectiveC)
- JavaScript has no concept in its language as it a Prototype-paradigm language (and so uses Duck-typing instead)
- IDL objects can often be represented 1:1 in a language's
interface
feature, assuming the language supports it