r/javascript • • Feb 20 '18

Optional Chaining may be coming to JavaScript

https://dev.to/sammyisa/optional-chaining-may-be-coming-to-javascript--4ff0
321 Upvotes

100 comments sorted by

View all comments

1

u/CCB0x45 Feb 20 '18

Really want this my code is littered with these. I also want a way to bind methods of JS classes with their own this. I have so many of these in my constructors: this.myfunc = this.myfunc.bind(this)

2

u/monvillalon Feb 20 '18

1

u/CCB0x45 Feb 20 '18

Yea but it should ebe handled without a plugin or library

1

u/Extracted Feb 21 '18

I love this one

1

u/soulsizzle Feb 20 '18

I also want a way to bind methods of JS classes with their own this.

Arrow functions do this.

1

u/CCB0x45 Feb 20 '18

I know arrow functions do this but it's nice to write using class syntax when you are writing a class.

1

u/SahinK Feb 20 '18

You probably shouldn't call a class member function from a different context anyway. Why do you need this?

For callbacks you can use

functionThatTakesCallback(() => this.method());

instead of

functionThatTakesCallback(this.method);

1

u/CCB0x45 Feb 20 '18

Event handlers callbacks is the typical case, you can use your syntax or use my syntax binding in the constructor, I think the way I do it is more readable when writing react and view classes. I'd just like a way to do it by default.

1

u/Extracted Feb 21 '18

Sending functions to child components in React and avoiding creating a new function on every render