6 ms·
A re-introduction to JavaScript - MDC
- samueladam 17y agocredits to boucher: http://news.ycombinator.com/item?id=601926 http://news.ycombinator.com/item?id=601926
- axod 17y agoIf you can't do anything without a book (Like me), get "JavaScript: The Definitive Guide by David Flanagan" I know you can print things out and bind them but it's just not the same.
- strider24 17y agoI thought I was the only one who needed books. I can't read long articles/tutorials online and always take a print or get a book.
- IsaacSchlueter 17y agoCrockford's "Javascript: The Good Parts" (aka "the butterfly book") is a much quicker read, and will result in better code.
- axod 17y agoI disagree. Probably a good idea to get both though. "The Good Parts" is interesting, but doesn't have a complete language reference.
- Hexstream 17y agoHaving almost no Javascript experience, I always thought the language looked messy but with this great introduction everything seems so clear. I found an error: switch(1 + 3): case 2 + 2: yay(); break; default: neverhappens(); } The ":" after the first line should be a "{".
- Sephr 17y agoMDC is a public wiki that anyone can edit. You can fix or change anything if you see fit (you don't need to fix it now, I fixed it).
- svat 17y agoThis a good introduction, but Douglas Crockford's A Survey of the JavaScript Programming Language [http://javascript.crockford.com/survey.html http://javascript.crockford.com/survey.html] is shorter and more detailed — and a perfectly adequate introduction if you already know other programming languages.
- Sephr 17y agoIt seems that the wiki page doesn't say anything about the `delete` and `let` operators. Those are very useful operators that should be read about. (just search `delete` or `let` on MDC)
- grayrest 17y agoNote that `let` was introduced in Javascript 1.7 and is not available in other browser implementations.
- boucher 17y agodelete can be useful, but it's not nearly as useful as it sounds. delete's only purpose is to remove a property name from an object. that is the only advantage it has over just nulling out a reference directly, and in most cases, the two techniques can be used interchangeably with no negative side effects. let is not useful to anyone doing browser based javascript work, because it doesn't work in any browser other than Firefox and derivatives. Getting a slightly different scope behavior is hardly worth throwing out 70-80% of potential users.
- axod 17y agoWrong. It's amazing this myth still gets perpetuated. Setting something to null, or even undefined, does not delete it. That's a swift ticket to leaking memory. Use delete. It's what it's for. >>> var test={foo:123} >>> test.foo = undefined >>> for (var i in test) { console.log(i); } foo >>> delete test.foo true >>> for (var i in test) { console.log(i); }
- boucher 17y agoNo, setting a variable to undefined doesn't delete the object contained in that variable (and I never said it did). Neither does calling delete. Delete gets rid of the variable itself, not the object it contains, which is precisely what I did say. JavaScript is a garbage collected language. As such, you, the developer, have no control over when an object can be ejected from memory. When a reference to your object no longer exists, it can be considered for collection. Until then, it can't. In your example, the number object (123) is eligible for collection in both cases. The difference has nothing to do with 123, but instead relates to the test object. In the first case, test will still have a foo property, which won't point to anything. In the second case, the property itself will be removed from the test object. It's (most likely) true that leaving the foo property intact means using more memory than if you delete it, but the memory used is less than actual object, and whether or not this qualifies as a leak is debatable. Which leaves my original statement: delete's only purpose is to remove a property name from an object This is particularly relevant when you iterate over the keys in an object for some reason. In the case of a global variable, this is just an implicit removal from the global/window object.
- lut4rp 17y agoAlso on HN, http://javascript.infogami.com/Javascript_in_Ten_Minutes http://javascript.infogami.com/Javascript_in_Ten_Minutes, is another good article.
- simonw 17y agoCool, I wrote these notes up for a conference tutorial I gave a few years ago, glad to see they've taken on a useful life of their own.
- tzury 17y agoafter 3 years of javascripting it still good to get a refresh for the language's core elements.