DEV Community

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

Collapse
 
avilapedro profile image
Pedro Ávila

Great article! Completely agree with you.

Another library that bothers me by forcing the use of this is Mongoose, here's an example from its docs:

// define a schema
var animalSchema = new Schema({ name: String, type: String });

// assign a function to the "methods" object of our animalSchema
animalSchema.methods.findSimilarTypes = function(cb) {
  return this.model('Animal').find({ type: this.type }, cb);
};

There are also functions that you can't import and destructure, because of this.

I would also like to add that this is an implicit argument for your functions, hence it can decrease the readability and comprehension of your code. BTW, that's why I hate using HOCs in React, it is hard to see how things relate to each other.

I also noticed that in your bitcoin-all-time-high project you're using Moment.js, although it's a great library, I would like to recommend you a more functional friendly one: date-fns.

Thank you for writing!

Collapse
 
dance2die profile image
Sung M. Kim • Edited

BTW, that's why I hate using HOCs in React, it is hard to see how things relate to each other.

Couldn't agree more. Render props partially fixes the problem but still you could get into pyramid of doom (unless you use a library like react-composer 😞)

And wow, bitcoin-all-time-high looks like a fun project. 💪

Collapse
 
joelnet profile image
JavaScript Joel

Totally agree. Render props is a great way to increase the visibility of your implementation by exposing values. I always go to a render props before a HOC.

It is a fun project. I can't wait for it to start tweeting again. Just gotta hit those all time highs again. lol

Collapse
 
joelnet profile image
JavaScript Joel

moment has been my goto forever. So long in fact that I never bothered looking for another. date-fns looks very interesting. thanks for the recommendation, I'll check it out!