Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unobtrusive Javascript Obfuscates Event Handling

You know what I liked best about obtrusive javascript? You always knew what it was going to do when you triggered an event.

<a onclick="thisHappens()" />

Now that everybody's drinking the unobtrusive kool-aid it's not so obvious. Calls to bind events can happen on any line of any number of javascript file that get included on your page. This might not be a problem if you're the only developer, or if your team has some kind of convention for binding eventhandlers like always using a certain format of CSS class. In the real world though, it makes it hard to understand your code.

DOM browsers like Firebug seem like they could help, but it's still time consuming to browse all of an element's event handler properties just to find one that executes the code you're looking for. Even then it usually just tells you it's an anonymous function() with no line number.

The technique I've found for discovering what JS code gets executed when events are triggered is to use Safari's Profiling tool which can tell you what JS gets executed in a certain period of time, but that can sometimes be a lot of JS to hunt through.

There's got to be a faster way to find out what's happening when I click an element. Can someone please enlighten me?

like image 986
Jesse Hattabaugh Avatar asked Oct 06 '09 18:10

Jesse Hattabaugh


People also ask

What are the unobtrusive JavaScript techniques?

In short, unobtrusive JavaScript is a way of writing JavaScript so that your site visitors are not shut out of your site for one of these reasons—even if your JavaScript is not working correctly for them, they should still be able to use your site, albeit at a more basic level.

What is the meaning of unobtrusive JavaScript explain us by any practical example?

Unobtrusive JavaScript is a general approach to the use of client-side JavaScript in web pages so that if JavaScript features are partially or fully absent in a user's web browser, then the user notices as little as possible any lack of the web page's JavaScript functionality.

Which of the following are the benefits of using unobtrusive JavaScript?

There are several benefits of using Unobtrusive JavaScript. Separation of concerns i.e the HTML markup is now clean without any traces of javascript. Page load time is better. It is also easy to update the code as all the Javascript logic is present in a separate file.

What is use of unobtrusive JavaScript in MVC?

One of the main goal of the unobtrusive support is to achieve the clear separation of both the HTML content and behavior, so as to enhance the page loading time and to make the code updation easier. The Essential JavaScript have separate integration library to achieve the Unobtrusive JS support.


1 Answers

Check out Visual Event... it's a bookmarklet you can use to expose events on a page.

like image 192
Mottie Avatar answered Oct 19 '22 22:10

Mottie