а что вам больше понравилось?
Use A + 0.5 | 0 instead of Math.round for positive numbers
Math.round(a) // before
a+.5|0 // after
Also, for negative number just change +.5|0 to -.5|0
Math.round(-a) // before
-a-.5|0 // after
Exploit the "falsiness" of 0
When comparing numbers, it's often shorter to munge the value to 0 first.
a==1||console.log("not one") // before
~-a&&console.log("not one") // after
Use the little-known .link method
Strings have a built-in .link method that creates an HTML link. This is used in @jed's linkify function.
html="<a href='"+url+"'>"+text+"</a>" // before
html=text.link(url) // after
Strings also have several other methods related to HTML, as documented here.
String coercion with array literal []
''+1e3+3e7 // before
[1e3]+3e7 // after
Omit () on new calls w/o arguments
new Object is equivalent to new Object()
now = +new Date() // before
now = +new Date // after
+ получаем сразу timestamp
Use []._ instead of undefined
""._
, 1.._
and 0[0] also work, but are slower. void 0 is faster than undefined but longer than the alternatives.
jed/140bytes
140bytes - A tweet-sized, fork-to-play, community-curated collection of JavaScript.
github.com