r/javascript • u/SvetlanaLucky • Sep 06 '12
JavaScript Tricks You May Not Know
http://www.learncomputer.com/javascript-tricks-you-may-not-know/
0
Upvotes
3
u/bart2019 Sep 06 '12
The dude should try to avoid words collapsed together, like
varmyVariable; deletesomeObj.val;
which should have been
var myVariable;
delete someObj.val;3
u/kristopolous Sep 06 '12 edited Sep 06 '12
agreed. It's totally sloppy. And these are all things that someone with a thorough JS education should know.
Here's an example of something this could have been, in firefox, try this:
function debugger() { alert ("hello world"); } debugger();Or the fact that the javascript duck typing can be overloaded. That's something most people actually don't know.
-1
4
u/kenman Sep 06 '12
Ugh, another problematic "tricks" article.
Deeply Nested Objects
This is not a "trick", it's JS 101. RTFM.
Static Local Variables
This one can be useful, but it's misnamed as they're not local.
Assertion
A better title would have been "how to make your own exceptions", which is a fancy way of demonstrating that you can use basically any function as an exception.
Custom Comparison and Sorting
Again, RTFM.
Tying Methods to Objects
Or, "let me demonstrate again how I haven't RTFM". See also: call(), apply(), and the prototypal inheritance.
Concatenating Strings vs. Array.join
I believe this one is flat-out wrong.