Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
"Interface" in MDN documentation for JS?

I have come across word "interface" so many times while reading through MDN documentation for JS, but never fully understood what does it refer to.

I know that there is no such thing as 'interface' in JS like in Java, C#, TypeScript and all other similar OOP languages.

As I know so far, an interface is just a collection of properties and methods definitions (not implementations) that a certain class must implement in order to conform to a particular interface, but that is not, once again, case for JS.

Now, let's imagine that MDN says some property of some object, let's say geolocation property of window.navigator returns GeolocationPosition/GeolocationPositionError object. Then we read that these objects are conform to GeolocationPosition/GeolocationPositionError interface(s).

Checking GeolocationPosition/GeolocationPositionError interfaces through console.dir returns that they are functions. So, does it mean that GeolocationPosition/GeolocationPositionError objects returned by accessing geolocation property on window.navigator are just objects created by GeolocationPosition/GeolocationPositionError functions?

So, does term interface on MDN documentation just refers to function, which creates objects with a certain properties and methods just like regular constructor functions?

Then why I can't generate a new GeolocationPosition/GeolocationPositionError object(s) using these GeolocationPosition/GeolocationPositionError functions and new operator?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Interface actually has a well defined meaning in the context of browser web APIs.

An interface in that context is a WebIDL interface. WebIDL is the "interface specification language" on top of which things like HTML and the DOM specifications are built on.

For example window.navigator implements the navigator interface:

[Exposed=Window]
interface Navigator {
  // objects implementing this interface also implement the interfaces given below
};
Navigator includes NavigatorID;
Navigator includes NavigatorLanguage;
Navigator includes NavigatorOnLine;
Navigator includes NavigatorContentUtils;
Navigator includes NavigatorCookies;
Navigator includes NavigatorPlugins;
Navigator includes NavigatorConcurrentHardware;

Interfaces are similar to what you would expect from "OO languages":

IDL fragments are used to describe object oriented systems. In such systems, objects are entities that have identity and which are encapsulations of state and behavior. An interface is a definition (matching interface InterfaceRest) that declares some state and behavior that an object implementing that interface will expose.

An interface is a specification of a set of interface members (matching InterfaceMembers). These are the members that appear between the braces in the interface declaration.

Interfaces in Web IDL describe how objects that implement the interface behave. In bindings for object oriented languages, it is expected that an object that implements a particular IDL interface provides ways to inspect and modify the object’s state and to invoke the behavior described by the interface.

An interface can be defined to inherit from another interface. If the identifier of the interface is followed by a U+003A COLON (":") character and an identifier, then that identifier identifies the inherited interface. An object that implements an interface that inherits from another also implements that inherited interface. The object therefore will also have members that correspond to the interface members from the inherited interface.

All from the WebIDL specification.

As for why you can't generate your own instances of the implementations browser provide for those interfaces?

I suspect GeolocationPositionError for example cannot be created because it is not exposed on window. If allowing that is useful to users you are welcome to open a feature request in the whatwg/html repo.

about 4 years ago · Juan Pablo Isaza Denunciar

0

In the MDN docs, the word interface is often being used to talk about APIs (Application Programming Interface). Indeed, the only thing you have to worry about as a developer is the API (not the implementation details behind the API).

Interfaces are only conceptual in JavaScript but they exist in some extending languages like TypeScript.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda