Node: Should switch classes to define class and fix name anonymous functions?

Created on 12 Oct 2016  Â·  6Comments  Â·  Source: nodejs/node

I saw some PRs that fix name anonymous functions.

Should switch to below way?

/lib/stream.js

class Stream extends EE {
  constructor () {
    super()
  }

  pipe () {
    // ...
  }
}
question

Most helpful comment

Only if it is already a class. If not, please don't. (The large change will likely make backporting far more difficult.)

All 6 comments

Only if it is already a class. If not, please don't. (The large change will likely make backporting far more difficult.)

The change would also break creation of objects without new.

@addaleax

creation of objects

module.exports = {

  pipe () {
  },

  end () {
  }

}

@fundon Stream() wouldn’t work because it’s a class :/

@addaleax Do you talk about this?

var stream = require('stream')
undefined
> stream.Stream()
undefined

@fundon If you turn Stream into a proper class, that breaks things like Stream.call(this); in the Writable constructor. You can somewhat work around that but once you’re at the double inheritance of Duplexes, things get really tricky…

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipesilvaa picture filipesilvaa  Â·  3Comments

vsemozhetbyt picture vsemozhetbyt  Â·  3Comments

Icemic picture Icemic  Â·  3Comments

addaleax picture addaleax  Â·  3Comments

srl295 picture srl295  Â·  3Comments