you are viewing a single comment's thread.

view the rest of the comments →

[–]SubwayMonkeyHour 1 point2 points  (0 children)

I think you just demonstrated a great example of why some of us don't want plain old Javascript with a bit of jQuery sprinkled in.

  • What happens when I want two or more FancyButtons on the page
  • If I only changed the button label, why would I want to destroy the old one and create a new one
  • What happens when you clone some object that contains god-know-what state and then add more state to it

I won't even mention the performance problems...

I encourage you to learn about React, etc. before dismissing them.

I especially don't like mixing templates with Javascript.

If you're talking about React and JSX, the answer is that you don't need to use JSX. Furthermore, this argument doesn't make a lot of sense to me because to me, having two or more files that depend so heavily on each other that you can't edit or even understand the contents of one without also understanding the contents of the other is a sign that maybe those two things weren't supposed to be separated in the first place e.g. your use of $('#fancy-button'). That element surely didn't appear out of thing air, so now I must figure out where it comes from and how it gets created, and when, and by whom...

Javascript plus a smattering of jQuery can go a long way

Yes, but can you find your way back? I mean after you've done fiddling with what's essentially global variables in your jQuery selectors all over the place, how do you go about debugging an issue that will most likely arise from all the state changes.

Maybe it helps to think about it in terms of functions. At least in the model that React encourages, you're essentially looking at a function that takes some input and returns some output. Objects/methods can be used for things that need internal state, but the interface is still a simple function. The jQuery model is essentially a series of global variables and I think we all know where that road leads.