I see where you are coming from and proposing new alternatives is always great, but in this case I, personally, think that nothis or fixthis are not a good approach. Unless JavaScript is completely redesigned in the years to come to make this work as expected (and I seriously doubt it. named functions and arrow functions already treat this differently, so you just choose what to use) and prevent all those pesky "gotcha!" moments we have every once in a while, adding a new dependency and new layer of complexity won't make anyone a better developer. It's far more useful to understand how this works and how you can use bind, call and apply to circumvent those problems then to add a new dependencie that will only mask those problems. I'd rather have someone on my team come to me and say "hey, I don't know why this isn't binding correctly" than see fixthis(this) on the code. this is not broken. It doesn't need to be fixed. this is just a rebelious teenager which we, sometimes, can't comprehend. Understand how this works and you'll see that correctly binding it is a far superior choice in the longterm than adding a dependency.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Unless JavaScript is completely redesigned in the years to come to make this work as expected (and I seriously doubt it
I agree. Can't be redesigned. It needs to remain backward compatible, so this will always remain and function as it does.
What I am proposing is the same thing others have proposed when suggesting programming languages should eliminate NULL (now considered the Billion dollar mistake).
If we can write our software in a way that eliminates an entire class of bugs, why would we not choose to do so?
If NULL is considered the Billion dollar mistake, how much is this going to cost us?
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 see where you are coming from and proposing new alternatives is always great, but in this case I, personally, think that
nothisorfixthisare not a good approach. Unless JavaScript is completely redesigned in the years to come to makethiswork as expected (and I seriously doubt it. named functions and arrow functions already treatthisdifferently, so you just choose what to use) and prevent all those pesky "gotcha!" moments we have every once in a while, adding a new dependency and new layer of complexity won't make anyone a better developer. It's far more useful to understand howthisworks and how you can usebind,callandapplyto circumvent those problems then to add a new dependencie that will only mask those problems. I'd rather have someone on my team come to me and say "hey, I don't know whythisisn't binding correctly" than seefixthis(this)on the code.thisis not broken. It doesn't need to be fixed.thisis just a rebelious teenager which we, sometimes, can't comprehend. Understand howthisworks and you'll see that correctly binding it is a far superior choice in the longterm than adding a dependency.I agree. Can't be redesigned. It needs to remain backward compatible, so
thiswill always remain and function as it does.What I am proposing is the same thing others have proposed when suggesting programming languages should eliminate NULL (now considered the Billion dollar mistake).
If we can write our software in a way that eliminates an entire class of bugs, why would we not choose to do so?
If NULL is considered the Billion dollar mistake, how much is
thisgoing to cost us?