The JavaScript Ninja (@jsninja) profile picture

Here on Twitter I will sporadically divulge sensitive information regarding JavaScript and its various abstractions...

Earth
Joined March 2009
The JavaScript Ninja retweeted
Did you watch @paul_irish live-fix some performance issues on a site with janky scrolling yet? youtube.com/watch?v=HAqjyCH_…
4
19
117
JS Promises are the ones you don't make to yourself.
1
1
Know thy self, know thy enemy (@uglyjs). A thousand battles, a thousand victories.
for (var i = -1, l = array.length; ++i < l;) // Yet another array looping 'pattern' (not original)
2
1
poll - "What identifier do you tend to use to reference out-of-scope contexts in your JavaScript code?" - twtpoll.com/tfvfko
1
1
Random value from array: ['which', 'word', 'i', 'wonder', '...?'][0|Math.random()*5]
2
~~n and n|n are the clear winners in the flooring benchmarks: http://ernestdelgado.com/archive/benchmark-on-the-floor/ (via @paul_irish)
1
Technically, you could use labelled compound statements ("blocks") to annotate pieces of code: http://bit.ly/an5l1U
http://www.spritely.net/ - Useful for CSS sprite animation
1
2
Answering Baranovskiy’s JavaScript quiz - http://www.nczonline.net/blog/2010/01/26/answering-baranovskiys-javascript-quiz/
Instead of (new Date()).getTime() ... You can just do +new Date
1
1
Optimise your Waterfall! http://www.phpied.com/free-falling-waterfalls/
Degradation of skills as a result of JS libraries - http://bit.ly/7Kpnmy
Want a free copy of the new jQuery cookbook (O'Reilly)? http://james.padolsey.com/javascript/the-jquery-cookbook/
1
1
Quick indexOf failure trick: !~string.indexOf(something) .... No need for ==-1
1
And, obviously, the other comparison operators work in a similar fashion. "a" <= "b" && "c" > "a"
"alpha" < "bravo" ... You can use the less-than operator on strings! (helps with lexicographical ordering)