Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: method chaining after the init function? #2

Open
pratyushgguptaa opened this issue Feb 13, 2022 · 0 comments
Open

feat: method chaining after the init function? #2

pratyushgguptaa opened this issue Feb 13, 2022 · 0 comments

Comments

@pratyushgguptaa
Copy link

Actually, I wanted to have this functionality:

myRL.init({ prompt: '> ' }).on('line', (line) => {
    //....
  })

Sometimes, we need only one listener and can be done in a single line otherwise we did like this:

const myRL = require('serverline')
 myRL.init({ prompt: '> ' })
  myRL.on('line', (line) => {
    // ...
  })

Instead we can do all of this in a single line:

require('serverline').init({ prompt: '> ' }).on('line', (line) => {
    //...
  })

I think we can achieve this using return this from the init function.
I tried (commit) and it works fine for me but is it the right way to do it?

Shall I make a PR or there is a better way to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant