I followed a little tutorial on Drag & Drop in HTML with Javascript, found here:
http://www.html5rocks.com/tutorials/dnd/basics/
The problem is, I’m working with an in-house style restriction. Meaning all documents have to be written to standards that everyone here uses.
For Javascript, one of them is to always write functions in the object-notation.
I.e.
var myFunction = function() {}
instead of
function myFunction() {}
In this tutorial, the events for the HTML5 drag & drop are added via the addEventHandler() function. This requires you use the normal notation, because if you use the object-notation, the addEventHandler() function trips over it for some reason.
I tried re-writing everything to be like this, without addEventHandler:
myElement.dragstart = function(e) {}
But non of it worked. Using the normal notation with addEventHandler however, everything works like a charm.
I just wanna make sure: am I overlooking something or should this work? Part of me suspects this is just not supported properly yet and you need to use addEventHandler. Is this the case?
Setting the
dragstartproperty vs usingaddEventHandler('dragstart', ...)is not just a matter of notation. You can and should stick withaddEventHandler. There should be no problem, however, using this "style:"Edit
Okay, so this doesn’t directly answer the question, but I feel it does need to be addressed in this context.
Writing
instead of
is not any sort of "object notation." The first is a function expression, since it’s part of an
AssignmentExpression. The second is a function declaration. What’s the difference? kangax explains it really well:Do the people who set the JavaScript code standards in-house really understand the subtle differences?