Skip to content

doc: replace util.inherits() with es6 classes extends #6512

Description

@eljefedelrodeodeljefe

util.inherits() is probably long unloved. With full class support it would be worth thinking of slowly deprecating it as weakly suggested in #4179 by @bnoordhuis .

Since this would strongly promote the class keyword for the JS world we would need to think about whether we want to do this and in which form. Personally I am not a big fan of it in general - especially since es6 proposed style would have methods on a non 0 indentation level. So we could think about the following:

cc @nodejs/documentation @jasnell

const EventEmitter = require('events')

class PureES6 extends EventEmitter {
  constructor() {
    super()
  }

  echo(val) {
    console.log(val)
  }
}

let es6 = new PureES6()
es6.echo('A Value')


class Mixed extends EventEmitter {
  constructor() {
    super()
  }

  _echo(val) {
    console.log(val)
  }
}

Mixed.prototype.echo = function echo (val) {
  this._echo(val)
}

let mixed = new Mixed()
mixed.echo('A Value')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions