Skip to content Skip to sidebar Skip to footer

Javascript Interfaces In Mdn

As far as I know JavaScript, being OOP based on prototypes - and not classes - do not contemplates interfaces, but relies instead on ducktyping. I can often see however in MDN onli

Solution 1:

It's not a class with a constructor that you can instantiate, so we don't call it a class. It's not a prototype object either.

MDN uses the term interface in the generic OOP meaning, which is not restricted to class-based inheritance but refers to a type definition with method signatures.

However, it also uses the term interface in the very specific context of the Web Interface definition language, which the web storage specification uses to define Storage as an interface indeed. These WebAPIs can be implemented in multiple languages (called "bindings"), though JS is most common. The WebIDL spec even defines how such an interface is to be represented in JavaScript (the "ECMAScript binding"), in particular that the linear inheritance of interfaces is implemented using prototype inheritance between interface objects and their .prototypes (basically as if using class Storage extends …). This means localStorage instanceof Storage and Storage.prototype.hasOwnProperty('getItem') work as expected.

Post a Comment for "Javascript Interfaces In Mdn"