JS: Interface
(new in JS: ECMAScript 2015)
What is JavaScript interface
An interface is a spec for a set of property keys and values .
- Any object that has all the properties as described by an interface's spec, is said to have (conform to) that interface.
- The property can be inherited property.
- By definition, many objects can have the same interface.
- By definition, a object can have many interfaces.
When a object confoms to interface X, we say that the object is “X object”. e.g. a object that conforms to the iterable interface is called “iterable object”.
There are 3 interfaces defined by the JavaScript spec:
Purpose of JavaScript Interface
JavaScript interface is the underlying mechanism for how Iterable Object works.