4 ms·
Javascript in Ten Minutes
- boucher 17y agohttps://developer.mozilla.org/en/a_re-introduction_to_javascript https://developer.mozilla.org/en/a_re-introduction_to_javasc... This continues to be pretty much the best JavaScript reference on the web.
- tumult 17y agoI've had a few beers, so I'm just going to come out and say it: JavaScript is a terrible language. The best thing it has going for it is that it's Turing Complete. "But wait!" you cry, "it's dynamic! It has lexical scope and lambdas! CLOSURES!" Too bad tail call elimination isn't in the spec. Or any kind of optimization on continuations or recursions. Yay running out of stack, tons of fun. I'll write a book called "JavaScript: the Best Part" and it will be one page long with "Parenscript is the best part of JavaScript" printed on it, with "(pray you don't end up 10-feet deep in a call stack)" in smaller type underneath. Maybe I should lay off the India pale ales and comments. edit: I had to use JavaScript for something a few weeks back, it was like being hit on the head with a hammer wrapped in a damp cloth. Let me show you what I mean: http://emgio.com/wow.png http://emgio.com/wow.png There are so many things wrong with this that I had to take a picture, which I now show to people whenever they try to argue in JavaScript's defense. The blue text is interpreter input and black is the return. Actually, JavaScript makes a fun benchmark race I guess, just because it's so ridiculously hard to write an optimized interpreter for.
- TomOfTTB 17y agoI think you miss the point. Some tools are made for precision while others are made for maximum functionality. The scalpel vs the Swiss Army Knife if you will. Javascript is horrible in many ways. It really wasn't even designed per se. It's just a mismash of hacks that Netscape put together with a few more hacks tacked on after the fact. But while that makes it messy it also makes it amazingly flexible. That's why it's become so popular.
- tumult 17y agoI didn't say it wasn't useful or popular. Just that it sucks! If it had just a few more things, it would be a lot easier to layer stuff on top of it, but we're kind of stuck with it now.
- TomOfTTB 17y agoIf you really hate it there's always Actionscript or if you're really brave you can even use C# or Visual Basic via Silverlight
- tumult 17y agoNo I'm totally with you, AS3 and C# are way better languages than JS. The CLR (and JVM, too) are all good ideas, I think that's what JS should have been instead of a weirdly dynamic C-syntax language with some useless prototype extension bolted on top (among countless other problems.) But JS, like most of the web technologies we're stuck with, weren't so much designed as they were a series of hacks layered on.. series of tubes.. anyway, I'm preaching to the choir I'm sure. Silverlight is actually a lot better than Flash in most ways that I've found, too bad it's not installed everywhere like Flash is. I would make some comment about MS being evil, but I think they're about on par with Adobe these days (except they still seem to employ engineers occasionally.)
- axod 17y agoI think you should step back, and go read "Javascript: The definitive guide". Also, for a good explanation of prototypical inheritance (Which is far from useless if you understand it), checkout the Douglas Crockford lectures (Vids on yahoo).
- ryanmahoski 17y agoHere is Crockford's 4 part series, concatenated: http://s3.amazonaws.com/2008/09/javascript.mp4 http://s3.amazonaws.com/2008/09/javascript.mp4 (178 MB).
- axod 17y agoYou should learn some more javascript. The language itself is pretty sweet. Individual implementations vary. Your image just shows you don't understand very much about the language. It's not "wrong" once you understand what it's doing and why. Show it to anyone who understands what is happening, and you'll look quite foolish. It's not massively complex once you read "Javascript: The definitive guide (O'Reily)" - the best book on js by a mile. var obj1 = {}; // var doesn't return anything, so the interpreter shows 'undefined'. var obj2 = {}; // same again obj1 == obj2; // Well no, they're different objects. So you'll get false var thing = {}; // thing[obj1] = "hi"; // OK this is an odd thing to want to do, but you're doing it anyway. // You're using an *object* (obj1), as a key. // The js thinks you're idiotic, but complies by calling the .toString() method, // and gets "[object Object]" or similar by default. // (You're free to override that on your object). thing[obj2] // Once again, you're using an object as a key // and acting surprised that js has changed it into a string. // So, you created an object and set thing["object Object"] = "hi" So instead of "Wow! js is retarded", my response to that code would be "Why is he trying to use objects as keys? and why is he surprised when js converts them to strings?" I recommend the above book to clear up things like this.
- tumult 17y agoRead it again, the problem is that it accepts it silently and does not indicate any sort of irregular behavior in an operation that shouldn't work that way. It just does it and then fails weirdly in the future. I fully understand how equality works in JavaScript (especially after making the mistake pictured.) Also, the existence of an "===" operator should be troubling. Many people writing JS don't even know it exists. edit: when you extend your reply in a large way, please append it with "edit:" or just make a new reply, thanks :]
- axod 17y agoWhy shouldn't it work that way??? It's silently doing type conversion for you - from an object to a string. That's desired behavior. Just as most languages presented with "foo"+12 would silently convert 12 to a string via the toString() method. What way do you think it should work? :/ An example of more sane usage: >>> var myv={} >>> var foo={toString:function(){return "12"}} >>> myv[foo]=34 34 >>> myv[12] 34 >> "Also, the existence of an "===" operator should be troubling. Many people writing JS don't even know it exists." You can't fault a language because some people don't make the effort to learn it properly.
- rimantas 17y agoThis should keep you away for a while: http://steve-yegge.blogspot.com/2008/06/rhinos-and-tigers.html http://steve-yegge.blogspot.com/2008/06/rhinos-and-tigers.ht...
- IsaacSchlueter 17y agoYou can bitch about how javascript sucks, and refuse to use it, or you can man up and write programs in the language that every web browser supports. Seems like a pretty easy choice to me. Yay running out of stack, tons of fun. Why aren't you using setTimeout to work around that limitation? Maybe I should lay off the India pale ales and comments. Yes, maybe you should.