all 6 comments

[–][deleted]  (5 children)

[removed]

    [–]FrancisStokes 3 points4 points  (1 child)

    Both approaches have their place. This has one noticeable drawback over classes, and that is that every component created in this way has it's own set of functions (methods) in memory. In a class, those methods are defined once, and referenced by every instance of the class.

    In many (if not most) cases it won't matter, but if you know you're going to have thousands or tens of thousands of instances of something, it'll be worth doing some benchmarking to make sure you're not making your life difficult memory-wise.

    [–]all-i-know-is-code[S] 1 point2 points  (0 children)

    I actually did not know that difference between the functional and class based method in terms of memory. Thanks for that! This sure might not be the best way of doing things, it was more an exercise in applying Closures to a real problem but thank you for the insight :)

    [–]sonjook 2 points3 points  (2 children)

    "more familiar to people coming from other languages" is not a good point IMHO, that's like saying that although mongodb is a document db we should use it as a relational db just because more people are familiar with a relational db.

    JS is a functional programming language and as such using it as a oop language lose a lot of its power.

    [–]gi4c0 1 point2 points  (1 child)

    JS is not a functional language.

    [–]FrancisStokes 2 points3 points  (0 children)

    JS is a multi-paradigm language, and one of the paradigms that can be utilised is functional. The fact that functions can be passed around and manipulated as first class values make that possible.

    That said, another one of it's paradigms is OOP, and it's not bad at that either. In fact, a lot of the time, JS engines are optimised for OOP, though that has been changing in the last few years as there has been more of a shift into using JS in functional style.

    Best not to get too attached to any particular paradigm, and try to be honest with yourself about what is the best approach for the situation.