Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
![](/static/devrant/img/pipeless-devrant-banner-white.png)
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
P1Ro3257yAlso another improvement could be adding and removing css class. Rather than inlining style.
-
crisz82387yYour javascript is pretty good. Use the performance improvement that other users suggested you.
Just once thing (related to css), don't set the property to a void string, use "initial" instead -
crisz82387yOh and you're not removing the elements from the DOM. It's ok if you've to hide/show several times in few seconds and if you have not many elements (<500 ligjtweight), otherwise consider remove the child instead of just hide the view
-
plusgut60377yIt's very obious that js is not a priority, don't mix business logic and dom manipulation. When the template changes your code will crash horribly. And this code is a mess when you try to test it.
Checking for > -1 isn't very readable, checking for === -1 and reverse the then-else part, is much better for understanding.
And don't do any performance improvements, it will fuck with your maintanability. But if you do anyway, measure it at least. -
lxmcf204227y@plusgut yesh I've been away from js for ages now and coming back to it isn't as easy as I remember!
I do plan to change most of this to be more readable and minimise it as much as I can -
plusgut60377y@BigMacca101 Oh and what I forgot to mention: never put your state in dom-elements, this will end in a clusterfuck.
-
mundo0349787y@Divisionbyzero exactly! Why????
(Messing with you)
I am asking about your pro tip on the first comment of this rant.
Why is declaring two variables in the first argument on the for better than what op did? -
Wombat105857y@mundo03 ah okay.
Its better because it calculates the arraylength once and not on every iteration of the for loop. That boosts performance. In my opinion loops have to be good in performance! -
lxmcf204227y@Divisionbyzero oh my god you're a genius!
I had no clue why it would be better but actually makes sense, thanks man! -
plusgut60377yIn my opinion you all should try to avoid writing clever code, but simple maintanable code. If you cache the length of the array, you will get an 'of undefined' exception when your code grows and you delete an element.
And the performance boost is minimal anyway. If you want to boost your performance don't use data-attributes to store your data, but a plain object.
And if you really want to cache something, cache your getElement, dom operations are the most expansive ones. -
plusgut60377y@Divisionbyzero Yep that's caching the value. You write in your variable a number. If the arraylength changes, your variable won't. Since Numbers are not references in js.
-
A1rPun2197y@Divisionbyzero @wizzzard
for(var i = children.length; i--;){
// set property with shorthand if ? : ;
}
Related Rants
Hmmm.... I wonder how obvious it is that JavaScript isn't my priority :-/
undefined
shitty web developer
js