Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
I think people have been trying to force OOP into JavaScript for a long time. I actually think classes were a mistake in JavaScript. But now that classes exist, people feel more and more comfortable with OO techniques.
JavaScript has Prototypal inheritance which is different than Class inheritance. But people coming from other languages start using JavaScript as if it were Class inheritance and that is where a lot of issues come from.
I feel like JavaScript is better suited for a functional reactive paradigm. Which doesn't require this at all.
The best solution is to code without this. Though sometimes you are stuck with this because of a 3rd library you are using.
If you look at the source code of nothis you will actually find that is exactly what it is doing behind the scenes. apply instead of call. github.com/joelnet/nothis/blob/mas...
So what you have suggested, is actually exactly how it works;)
There's no one best solution to every problem; what you're mentioning is subjective from case-to-case, dev-to-dev. You mention the use of functional reactive paradigm over OO, but then you're accessing this.event in your example; EventEmitter doesn't currently endorse that.
OO and Functional have their pros/cons and it's up to the infrastructure, architects, and developers to implement what works best as the solution to the problem, which is question to endless iterations of improvement over time.
We can sit here all day arguing about this, but I think it's clear where we both stand.
Ciao
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think people have been trying to force OOP into JavaScript for a long time. I actually think classes were a mistake in JavaScript. But now that classes exist, people feel more and more comfortable with OO techniques.
JavaScript has Prototypal inheritance which is different than Class inheritance. But people coming from other languages start using JavaScript as if it were Class inheritance and that is where a lot of issues come from.
I feel like JavaScript is better suited for a functional reactive paradigm. Which doesn't require
this
at all.The best solution is to code without
this
. Though sometimes you are stuck withthis
because of a 3rd library you are using.If you look at the source code of
nothis
you will actually find that is exactly what it is doing behind the scenes.apply
instead ofcall
. github.com/joelnet/nothis/blob/mas...So what you have suggested, is actually exactly how it works;)
There's no one best solution to every problem; what you're mentioning is subjective from case-to-case, dev-to-dev. You mention the use of functional reactive paradigm over OO, but then you're accessing
this.event
in your example;EventEmitter
doesn't currently endorse that.OO and Functional have their pros/cons and it's up to the infrastructure, architects, and developers to implement what works best as the solution to the problem, which is question to endless iterations of improvement over time.
We can sit here all day arguing about
this
, but I think it's clear where we both stand.Ciao