3 ms·
I am going to root for bloated jQuery to save my life! $('.tpm_sensors').forEach(function(sensor) { if (sensor.pressure < threshold) fixBeforeIDie(); }); vs:
by pupdogg 8y ago
I am going to root for bloated jQuery to save my life!
$('.tpm_sensors').forEach(function(sensor) { if (sensor.pressure < threshold) fixBeforeIDie(); });
vs:
var tpm_sensors = document.getElementsByClassName('tpm_sensors');
for (var i = 0, len = tpm_sensors.length; i < len; i++) {
var sensor = tpm_sensors[i];
if (sensor.pressure < threshold) fixBeforeIDie();
}
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- capsulecorp 8y agoNo need to load a slow bloated library. Learn modern DOM methods. Reading does wonders, my opinion.
- LorenzA 8y agodocument.querySelectorAll('.tpm_sensors').forEach((sensor) => {if (sensor.pressure < threshold) { fixBeforeIDie(); }});
- ulucs 8y agoand you usually define $ and $$ as querySelector and querySelectorAll at the beginning of the file if you don't like writing them all out, so they're exactly the same length
- IgorPartola 8y agoI remember the mess that came before jQuery. This is quite literally what we did back then, just with a custom made snippet of JS for finding by id and by class. It sucked. I mean to me Bootstrap is just a black box library, I don’t care how it works as long as it does. But this is going to suck for those working on its code.
- phponpcp 8y agoThen this breaks in older browsers because forEach isn't a method on a NodeList. So you have to polyfill in features to do [...document.querySelectorAll('.tpm_sensors')].forEach(...);
- efdee 8y ago> TypeError: $(...).forEach is not a function And so it starts. jQuery uses .each, not .forEach. So you fix that. But stuff still doesn't work. Right, because jQuery's .each passes the index as first parameter and the element as second (or this). jQuery trips me every single time.