Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Youngwerth
10,188 PointsIs there a reason onreadystatechange doesn't follow the camelCase convention?
For example:
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
document.getElementById('ajax').innerHTML = xhr.responseText;
}
};
notice xhr.onreadystatechange is not camelCased but xhr.responseText is. Is there a reason for this that I've missed?
1 Answer
Nicholas Hebb
18,872 PointsA lot of the javascript events don't follow the camel case conventions (onclick, onmouseover, ...). So I guess the rule of thumb is that your methods should be camel case, but don't always expect events to follow suit because many were created before casing conventions became uniform.
Andrew Youngwerth
10,188 PointsAndrew Youngwerth
10,188 PointsThanks! It hadn't even occurred to me that those events didn't follow camelCase.