6 ms·
Your comment might be useful or interesting if you explained which WTF moments affected you in particular, or even just which other languages you've used. As it
by oneeyedpigeon 12y ago
Your comment might be useful or interesting if you explained which WTF moments affected you in particular, or even just which other languages you've used. As it is, it's not adding much to the conversation which is why you've been downvoted.
- collyw 12y agoIts well documented: https://wiki.theory.org/YourLanguageSucks#JavaScript_sucks_because https://wiki.theory.org/YourLanguageSucks#JavaScript_sucks_b...
- andyhmltn 12y agoYou didn't link to it and it's still pretty irrelevant to the original discussion.
- virmundi 12y agoI'm actually trying to write a book about that myself. It's called "JavaScript es basura caliente: Learning JavaScript in Anger". The goal of the book is not to rag on JS. That's not new or really interesting in its own right. The goal is to walk people through the oddities of the language such as identity loss when passing a function from an object to something else (the good old this == window rather than self). There are interesting, and annoying, things about JS that are non-obvious to people from a different language like Java or C#. There are other issues like testing and package management that are either assumed or glossed over. The JS community knows about them. Unfortunately for most of us, the responses to the language's weakness and ecosystem strengths are dispersed through the interblogs. In fact from personal use of JS and some research on the book, I'm moving to a functional approach with JS. OO in Ecma5 is a pain. Pure (or Clojure like) functional can work with a bit of help from Underscore. That pardigm seems to fit the mentality of JS better too. https://leanpub.com/javascriptesbasuracaliente https://leanpub.com/javascriptesbasuracaliente
- deleted 12y ago[deleted]
- sarciszewski 12y agoSome WTF moments in Javascript, courtesy of Gary Bernhardt: var foo = ["10", "10", "10"]; foo.map(parseInt); // Returns [ 10, NaN, 2 ] [] + [] // "" [] + {} // {} {} + [] // 0 {} + {} // NaN var a = {}; a[[]] = 2; alert(a[""]); // alerts 2 alert(Array(16).join("wat" - 1) + " Batman!"); Press F12 and use the Console to verify these if you're skeptical.
- emehrkay 12y agoThe first one is easy to understand though. parseInt takes two arguments: $thing_to_change and $radix; map iterates over an array and feeds it $value and $index. You're getting parseInt("10", 0); parseInt("10", 1) and parseInt("10", 2); The fix would be to partially apply parseInt with your defined radix; var foo = ["10", "10", "10"]; var base10 = function(val){ return parseInt(val, 10); }; x = foo.map(base10) [10, 10, 10]
- sarciszewski 12y agoA lot of the ones he presented are easy to understand. It's still a WTF when you run into it though.
- emehrkay 12y agoI guess my question is: what would have to change, in the last example, to make it not WTF to you? To me it seems pretty straight-forward what is happening.
- beejiu 12y agoAll you have done is used a function without understanding what it was doing, or reading the documentation. Most JS developers know how parseInt works, and even if they run into this problem, would quickly discover the cause. I don't see how this is a flaw of Javascript; it could happen to a developer of any language, if their strategy is 'well, it looks like it'll work'.
- 12y ago
- _broody 12y agoMost of these WTF examples basically boil down to JS doing type coercion willy-nilly. This 'feature' makes writing conditionals slightly shorter, in exchange for introducing the possibility of massive bugs everywhere in your code at any moment. Seriously, f* JS type coercion. The other misfeature I hate is that accessing undefined properties doesn't raise an error (then, but you can be sure it will make your program blow up a bit later). Typescript helps to solve both.
- dccoolgai 12y agohttp://leftoversalad.tumblr.com/post/103503118002?utm_source=javascriptweekly&utm_medium=email http://leftoversalad.tumblr.com/post/103503118002?utm_source...
- _random_ 12y agoHere you go: http://wtfjs.com http://wtfjs.com