Title: util.inherits cannot be used with ES6 classes · Issue #3452 · nodejs/node · GitHub
Open Graph Title: util.inherits cannot be used with ES6 classes · Issue #3452 · nodejs/node
X Title: util.inherits cannot be used with ES6 classes · Issue #3452 · nodejs/node
Description: I'm experimenting with ES6 classes and noticed I was unable to use util.inherits to inherit EventEmitter into the prototype of my class. 'use strict'; var util = require('util'); var EventEmitter = require('events').EventEmitter; class x...
Open Graph Description: I'm experimenting with ES6 classes and noticed I was unable to use util.inherits to inherit EventEmitter into the prototype of my class. 'use strict'; var util = require('util'); var EventEmitter =...
X Description: I'm experimenting with ES6 classes and noticed I was unable to use util.inherits to inherit EventEmitter into the prototype of my class. 'use strict'; var util = require('util')...
Opengraph URL: https://github.com/nodejs/node/issues/3452
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"util.inherits cannot be used with ES6 classes","articleBody":"I'm experimenting with ES6 classes and noticed I was unable to use `util.inherits` to inherit `EventEmitter` into the prototype of my class. \n\n``` javascript\n'use strict';\nvar util = require('util');\nvar EventEmitter = require('events').EventEmitter;\n\nclass x {\n constructor() {\n EventEmitter.call(this);\n }\n emitEvent() {\n this.emit('event emitted!');\n }\n}\n\nutil.inherits(x, EventEmitter); // Fails\n```\n\nThe error is `TypeError: Cannot assign to read only property 'prototype' of \nclass x {\n constructor() {\n EventEmitter.call(this);\n }\n emitEvent() {\n this.emit('event emitted!');\n }\n}`\n\nI was able to get inheritance to work using `class x extends EventEmitter`, but using `extends` means my class can't be a subclass of anything besides `EventEmitter` unless I make `EventEmitter` the root class.\n\nThoughts on this?\n","author":{"url":"https://github.com/zen-crab","@type":"Person","name":"zen-crab"},"datePublished":"2015-10-20T18:42:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/3452/node/issues/3452"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4a91dfc3-6e48-d9dd-ab55-180b8a2aef1b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9FA:34D244:508E4A8:71BFBA8:6A4FDF84 |
| html-safe-nonce | 5a1acf3cbe995cfee39b5254f4da0dfe7bb47ede9ffe806553caaf05e05f7ac9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUZBOjM0RDI0NDo1MDhFNEE4OjcxQkZCQTg6NkE0RkRGODQiLCJ2aXNpdG9yX2lkIjoiODQ1MDk3OTEwNDUzOTI3MTA0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d93c2b16997efeb1e494d4b2d0705e0a41d925baaf02fb7399f9d837af6f509e |
| hovercard-subject-tag | issue:112433365 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/3452/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cd07aea4d2e381537e1d521ef3215d3b974c9c796aea0eb76861c129cd2ce1bf/nodejs/node/issues/3452 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cd07aea4d2e381537e1d521ef3215d3b974c9c796aea0eb76861c129cd2ce1bf/nodejs/node/issues/3452 |
| og:image:alt | I'm experimenting with ES6 classes and noticed I was unable to use util.inherits to inherit EventEmitter into the prototype of my class. 'use strict'; var util = require('util'); var EventEmitter =... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zen-crab |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19b98c3d9767bb8a56238a89ff8401d1cbdf3bc5c353799aacf49fe6c76b4b7c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 142593e66413bbae27fd485859993597d5a3b104 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width