DEV Community

Discussion on: Rethinking JavaScript: The complete elimination and eradication of JavaScript's this.

Collapse
 
ddonprogramming profile image
Decebal Dobrica

I love the use of core-decorators, in particular @autobind, but the removal of "this" does not make any sense for me if OO is not ditched as well, you are supposed to use the current object in it's implementation. FP is amazing and the tools of it are plenty to go for this day and age. Great post.

Collapse
 
joelnet profile image
JavaScript Joel

While I do advocate FP over OO (in JavaScript), I don't think this is a keystone of OO. There are plenty of ways to create an Object without using this.

const Thing = () => {
  const someMethod = () => {}
  const anotherMethod = () => {}

  return {
    someMethod,
    anotherMethod
  }
}

const x = new Thing()
x.someMethod()

Much like null, this also introduces an entire class of bugs.

If we can completely eliminate an entire class of bugs (NullReferenceException) with null, then why can't we do the same with this?

Collapse
 
ddonprogramming profile image
Decebal Dobrica

haha, true. As a polyglot I can confirm this approach is rather difficult to stick to.

Thread Thread
 
joelnet profile image
JavaScript Joel

I agree, it is difficult. I come from a C# background. Very OOP. And at some point, I also wanted JavaScript to be like C#. Classes, inheritance, overrides, overloads, blah blah.

Heck, a few years ago I wrote WorkflowJS which was a recreation of Windows Workflow Foundation 4 in JavaScript. LOL

But of course this came with problems most of which I outlined in How I rediscovered my love for JavaScript after throwing 90% of it in the trash.

Life became simpler after understanding FP. There's just so much unnecessary complexity that comes with OOP.