{"action":"created","issue":{"url":"https://api.github.com/repos/openlayers/openlayers/issues/8771","repository_url":"https://api.github.com/repos/openlayers/openlayers","labels_url":"https://api.github.com/repos/openlayers/openlayers/issues/8771/labels{/name}","comments_url":"https://api.github.com/repos/openlayers/openlayers/issues/8771/comments","events_url":"https://api.github.com/repos/openlayers/openlayers/issues/8771/events","html_url":"https://github.com/openlayers/openlayers/issues/8771","id":366043286,"node_id":"MDU6SXNzdWUzNjYwNDMyODY=","number":8771,"title":"Should we get rid of instanceof checks?","user":{"login":"ahocevar","id":211514,"node_id":"MDQ6VXNlcjIxMTUxNA==","avatar_url":"https://avatars1.githubusercontent.com/u/211514?v=4","gravatar_id":"","url":"https://api.github.com/users/ahocevar","html_url":"https://github.com/ahocevar","followers_url":"https://api.github.com/users/ahocevar/followers","following_url":"https://api.github.com/users/ahocevar/following{/other_user}","gists_url":"https://api.github.com/users/ahocevar/gists{/gist_id}","starred_url":"https://api.github.com/users/ahocevar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahocevar/subscriptions","organizations_url":"https://api.github.com/users/ahocevar/orgs","repos_url":"https://api.github.com/users/ahocevar/repos","events_url":"https://api.github.com/users/ahocevar/events{/privacy}","received_events_url":"https://api.github.com/users/ahocevar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-02T19:21:39Z","updated_at":"2018-10-03T17:35:20Z","closed_at":null,"author_association":"MEMBER","body":"Reviewing pull requests that fix TypeScript type errors, I saw that `instanceof` checks were introduced in many places. Although it's a clean and readable way to check whether a value we get is what we expect, I'm a bit concerned about this for two reasons:\r\n\r\n 1. **Performance**: some of our `instanceof` checks (e.g. event conditions for move events in `ol/events/condition.js`) are executed very often, and according to https://jsperf.com/duck-vs-instanceof they are 3 times slower than duck type checks.\r\n\r\n 1. **Environments where the  [ol](https://npmjs.com/package/ol) package is used in multiple versions**: In these cases, `instanceof` checks will not return true when the constructors are from different versions of `ol`. We have seen this problem often in the past e.g. with `ol/Style` instances created by third party libraries (e.g. the [ol-mapbox-style](https://npmjs.com/package/ol-mapbox-style) package). \r\n\r\nWhat do others think? Should we try to get rid of `instanceof` checks?"},"comment":{"url":"https://api.github.com/repos/openlayers/openlayers/issues/comments/426727582","html_url":"https://github.com/openlayers/openlayers/issues/8771#issuecomment-426727582","issue_url":"https://api.github.com/repos/openlayers/openlayers/issues/8771","id":426727582,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNjcyNzU4Mg==","user":{"login":"ahocevar","id":211514,"node_id":"MDQ6VXNlcjIxMTUxNA==","avatar_url":"https://avatars1.githubusercontent.com/u/211514?v=4","gravatar_id":"","url":"https://api.github.com/users/ahocevar","html_url":"https://github.com/ahocevar","followers_url":"https://api.github.com/users/ahocevar/followers","following_url":"https://api.github.com/users/ahocevar/following{/other_user}","gists_url":"https://api.github.com/users/ahocevar/gists{/gist_id}","starred_url":"https://api.github.com/users/ahocevar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahocevar/subscriptions","organizations_url":"https://api.github.com/users/ahocevar/orgs","repos_url":"https://api.github.com/users/ahocevar/repos","events_url":"https://api.github.com/users/ahocevar/events{/privacy}","received_events_url":"https://api.github.com/users/ahocevar/received_events","type":"User","site_admin":false},"created_at":"2018-10-03T17:35:20Z","updated_at":"2018-10-03T17:35:20Z","author_association":"MEMBER","body":"Ok, I'm working on a pull request."}}
{"actor":{"display_login":"ahocevar"}}