If you're looking for something that is equivalent to your original code, keep in mind that jQuery as a tool is designed to bridge browser inconsistencies. The following is functional on newer browsers that support addEventListener, document.querySelector, and dataset. Also note that mouseenter and mouseleave were originally proprietary to Internet Explorer, and other browsers are only recently adopting the two events. YMMV.
Option 1
This works, but I'm not super familiar with the implications of storing the timer as an arbitrary property of the DOM element. This is better than option 2 in that it works for any opaque value timer (given that the specification for setTimeout is that the return value can be any value, not just serializable values like numbers).
var element = document.querySelector('#selector');
element.timer = null;
element.addEventListener('mouseenter', function() {
// you probably want to ensure that element.timer is not null first
// just replicating the original code
clearTimeout(element.timer);
element.timer = setTimeout(function() {
// do stuff
}, 50);
});
element.addEventListener('mouseleave', function() {
clearTimeout(element.timer);
element.timer = setTimeout(function() {
// do the other stuff
}, 300);
});
Option 2
This option assumes that setTimeout returns a value which is serializable, which is generally true for browsers (but not true for environments like Node.js).
var element = document.querySelector('#selector');
element.dataset.timer = '';
element.addEventListener('mouseenter', function() {
// you probably want to ensure that element.timer is not null first
// just replicating the original code
clearTimeout(element.timer);
element.dataset.timer = setTimeout(function() {
// do stuff
}, 50);
});
element.addEventListener('mouseleave', function() {
clearTimeout(element.timer);
element.dataset.timer = setTimeout(function() {
// do the other stuff
}, 300);
});
Note that both options assume you don't care about the element variable cluttering any containing namespaces. Use an IIFE if that concerns you.