Methods
isEventTarget(value) → {Boolean}
Returns if a value is an EventTarget, which means that it is able to dispatch and receive events. This is determined via duck-typing and not via class inheritance check, since this method is not about type-safety, but the question if we can use the target for events, which is simply determined by three essential object methods: addEventListener, removeEventListener and dispatchEvent. All objects supporting these are fine with us.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | the value to check |
Returns:
true if value supports event methods
- Type
- Boolean
Example
if( isEventTarget(target) ){
target.dispatchEvent(new CustomEvent('foobar'));
}