Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have a few answers to your questions - at least from my point of view. Answers to questions like this really are dependent on your experience and preferences.</p> <p>1) I would say that unobtrusive JavaScript is going to lead to less code overall especially if you are reusing the JavaScript methods.</p> <p>2 &amp; 3) I'm going to go with unobtrusive JavaScript for both of these. When the JavaScript is decoupled from the page structure you have a better idea of what that specific piece of code does and can test it as well as know that you have tests for those methods. Mixed code is generally (in my experience) much more difficult to get good test coverage. This will help keep code less error-prone.</p> <p>One issue with decoupled js is if you remove a feature you may leave code behind or remove dependent code. Of course this is why you should have automated tests and good coverage.</p> <p>4) I think inline js is easier to understand because it is all right there however anything over one line and you are already reducing readability so you might as well just go unobtrusive all the way for the other benefits. Unobtrusive js also makes it much easier to maintain and document for other team members.</p> <p>5) In my experience this a wash. You have to provide extra methods either way.</p> <p>As an end note, I agree that Rails 3 also provides much better support for unobtrusive js and I view it as a best practice. I just started fixing up an old application for a client and with the mixed views of html, js, logic, it is really a pain to grasp what they are trying to accomplish. If things were separated it would be much easier to take in.</p> <p>I hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload