14 ms·
A Reintroduction to JavaScript
- CmonDev 13y agoIf you wanted to find a friend for someone would you keep trying to introduce them to same stupid ugly person, while saying: "Look! He/she is wearing make-up this time!".
- kajecounterhack 13y agoThis isn't a productive comment. Whether you like it or not js is here to stay. It's the language of the web (and more). A lot of new capabilities are being exposed via browser makers (e.g peerconnection, webrtc) which only serve to increase its power. Calling it stupid and ugly is your unsubstantiated opinion. (Infinitely more useful: say why this is your opinion.) I think this is a nice intro to the language. Why it's being posted now though is a little puzzling considering it's from 2006. It is obviously still relevant and interesting but readers should realize it's not very recent.
- lobotryas 13y agoI've never gone very deep with JS. Anything you could recommend, off the top of your head, for a more recent look at the language?
- CmonDev 13y agohttp://wtfjs.com http://wtfjs.com
- thousande 13y agoThere has been added a lot of new features to the browser, but the core language (EcmaScript) has not evolved much for a while. * Overview: https://rawgithub.com/whatwg/html-differences/master/Overview.html#apis https://rawgithub.com/whatwg/html-differences/master/Overvie... The next thing is JavaScript "next" or Ecma Script 6 * http://wiki.ecmascript.org/doku.php?id=harmony:proposals http://wiki.ecmascript.org/doku.php?id=harmony:proposals You can use Traceur if you want to try out ES6 features today More info: https://github.com/google/traceur-compiler https://github.com/google/traceur-compiler These days there is a lot of things going on in the tooling section Build: * Grunt: http://gruntjs.com/ http://gruntjs.com/ - a lot of grunt- tasks at http://npmjs.org/ http://npmjs.org/ * Newest kid in town: https://github.com/gulpjs/gulp https://github.com/gulpjs/gulp Modulization and dependency management: * http://en.wikipedia.org/wiki/CommonJS http://en.wikipedia.org/wiki/CommonJS * http://browserify.org/ http://browserify.org/
- aye 13y agoJavaScript Spessore, by Reginald Braithwaite: https://leanpub.com/javascript-spessore https://leanpub.com/javascript-spessore
- raganwald 13y agoThank you, although please note that "JavaScript Spessore" is (a) a work-in-progress, and (b) about "Thinking in objects" more than "The idiomatic way to program in JavaScript.
- ldarcyftw 13y ago> js is here to stay. It's the language of the web In the same manner as assembler is here to stay. Assembler is "the language of the computer". Not that many people write assembler these days though, majority moved on to languages more suited to their needs.
- viach 13y agoDid you just mean Java 7?
- Trufa 13y agoYou got the metaphor wrong. "Hey, look, this is Jenna. You'll have to work with her for the next 10 years. She's hard to figure out and grumpy at times, but if you treat her right she'll play along. Actually if you get to know her, she can be a great asset."
- pekk 13y agoPlease stop blaming users. If Jenna is a royal pain in the ass by design, her being a pain in the ass isn't the user's fault for not "treating her right." Whether it is an asset to work around her crap or not. There's all kinds of things which are an asset to know but are a huge pain in the ass to work with, and somehow we are allowed to complain about most of those but god help the man who complains about Jenna in public. She's connected.
- raganwald 13y agoPaul Graham once said, "Where there's muck, there's brass." He explained that there is often an opportunity to be had if you dive deep down into ugly, unpleasant things and find a way to make them work.
- CmonDev 13y agohttp://www.phrases.org.uk/meanings/408900.html http://www.phrases.org.uk/meanings/408900.html "Don’t make idols for yourselves" is another old expression.
- sgon00 13y ago“Everything that can be written in JavaScript will eventually be written in JavaScript”. – Atwood’s law "Everything’s Gone JavaScript" "The future is written in Javascript" JavaScript is now an integral part of several operating systems. JavaScript is also moving quickly into the hardware world.
- welder 13y agoThe example of JavaScript's prototype here is the best I've ever seen! It's in the "Custom Objects" section.
- exodust 13y agoYeah it's good. The whole thing is nicely presented with great examples. Bookmarked.
- inglor 13y agoSome mistakes there, will fix. `null` is most certainly not an object.
- notjosh 13y agoI got this in an interview once as a curveball. It's most certainly an object in Javascript! > typeof null "object" Contrast that with: > typeof undefined "undefined" Go figure :)
- saurik 13y agotypeof null returns "object", but I do not believe it is correct to claim that null "is an object". It is my understanding (maybe a misunderstanding, I will happily state) from reading a ton of comments from Brendan Eich in various places that typeof null is "object" for historical reasons involving the way reference types were implemented in the original JavaScript VM.
- inglor 13y agoExactly, if people are interested I'll gladly find the reference to the relevant esdiscuss thread.
- raganwald 13y agoIt is correct to say that typeof(null) returns the string 'object' because of a bug that is now written into the standard to prevent old software from "breaking" if they fixed this. It is not ever correct to say that null in JavaScript is an object. Just ask javaScript itself: Object.getPrototypeOf(null) //=> TypeError: Object.getPrototypeOf called on non-object
- inglor 13y agoThat's a mistake in the specification. We tried to fix that experimentally but it broke too many sites. If you check the language specification you can see that `null` is in fact not an object - it's something called a 'primitive value type', just like numbers, strings, undefined and booleans. Here http://es5.github.io/#x8 http://es5.github.io/#x8 :)
- ritchiea 13y agoIt is probably a good idea to add 2006 to the title since that's the date of the last update [1]. 1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript#Original_Document_Information https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re...
- psibi 13y agoThanks, updated the title.
- hmsimha 13y agoread author's comment above.
- inglor 13y agoI've altered it today, fixed in MDN nice catch thanks.
- mwill 13y agoIs that the last date? There's a mention of pre-2013 on the page? Edit: Just noticed inglor say it was a caching issue and the page was updated today.
- frik 13y agoIt's a wiki, see the page's history: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript$history https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re... Maybe remove the "2006" from the headline (again).
- psibi 13y agoNot able to edit the headline now.
- jokoon 13y agostill a better introduction to javascript: https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat (with a little bit of ruby)
- chewxy 13y agoNo. It's not a good introduction to JS. JS is very WTF worthy (I should know, I'm writing a book on how to write asshole Javascript), but the WAT talk is NOT a good intro
- badman_ting 13y agoAgreed, it's a collection of trivia. Very WTF-worthy trivia but if your code is doing basically any of the things listed in that talk, something has gone terribly awry.
- deleted 13y ago[deleted]
- cellover 13y agoI am currently in the process of re-learning JavaScript from scratch. And I found the light: 1. Douglas Crockford videos: http://www.yuiblog.com/crockford/ http://www.yuiblog.com/crockford/ 2. Eloquent JavaScript intermediate level tutorials: http://eloquentjavascript.net/contents.html http://eloquentjavascript.net/contents.html
- acjohnson55 13y agoIf you truly want to master the language, Reg Braithwaite's stuff is incredible. I think Javascript Allongé is one of the best programming books I've read on any topic, and it's free online: http://leanpub.com/javascript-allonge http://leanpub.com/javascript-allonge.
- cellover 13y agoExcellent resource, thank you very much for posting!
- johncoltrane 13y agoIf only it wasn't full of hipster coffee analogies…
- taway2012 13y agoCrockford's "Javascript: the Good Parts" is a very good book.
- badman_ting 13y agoCrockford is largely how I learned too. He's a crank but I've found that to be a useful property when I was learning JS. (Or really, re-learning it as you say)
- __derek__ 13y agoCheck out the book Effective JavaScript[1], too. [1] http://effectivejs.com/ http://effectivejs.com/
- babuskov 13y agoSince I started using JS heavily lately, it's nice to be reminded of some things. Thanks for posting. One question though, it says: If you want to append an item to an array, the safest way to do it is like this: a[a.length] = item; // same as a.push(item); a.push() variant seems more elegant to me. Why is a[] variant "safer"?
- bpierre 13y agoIt must be for the compatibility, Array.prototype.push() has been added to IE 5.5: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push#Browser_compatibility https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- unstabilo 13y agoBoth methods are equally safe, what the author meant is that both are safer than a[14] = item or a[myCounter] = item.
- aaronetz 13y agoOff-topic, but I must say that this site handles resizing very well. I really appreciate it when a website seamlessly transitions from desktop-size to mobile-size layout. Sometimes I just like having my browser window shrunk down (or zoomed in for viewing from farther away), which means that with most sites I have to scroll horizontally, which is not very usable.
- tunnuz 13y agoOld but gold.
- mr-ron 13y agoOne of my favorite tutorials from John Resig: http://ejohn.org/apps/learn/ http://ejohn.org/apps/learn/
- andrethegiant 13y agoI didn't know about the memory leak stuff! Any tools out there to help identify this in your code?
- lhorie 13y agoThere's Dynatrace, IESieve and Drip (the latter two's websites are now defuct though), but IIRC, the IE team fixed the memory leak issue via a service pack or hotfix a few years ago.
- henryw 13y agoThe "even nicer [array for loop] idiom" is pretty cool: for (var key = 0, value; value = someArray[key++];) { // value is already defined by for loop console.log('index: ' + key, 'value: ' + value); } Also, I finally understand closures: "Whenever JavaScript executes a function, a 'scope' object is created to hold the local variables created within that function. It is initialised with any variables passed in as function parameters. This is similar to the global object that all global variables and functions live in, but with a couple of important differences: firstly, a brand new scope object is created every time a function starts executing, and secondly, unlike the global object (which in browsers is accessible as window) these scope objects cannot be directly accessed from your JavaScript code... A closure is the combination of a function and the scope object in which it was created."
- Drakim 13y agoUnless I'm mistaken, wouldn't this loop terminate prematurely if the array contains any falsy value, such as undefined, null, false, NaN, or 0?
- joebadmo 13y agoYes, there's a note right after: Note that this trick should only be used for arrays which you know do not contain "falsy" values (arrays of objects or DOM nodes for example). If you are iterating over numeric data that might include a 0 or string data that might include the empty string you should use the i, len idiom instead.
- Wintamute 13y agoYou're correct. Seems like a pretty useless/dangerous idiom to me. How often can you be sure that in 100% of cases your loop will never iterate a 0, an empty string or some other falsey value?
- al2o3cr 13y agoThe above code will print out an off-by-one index for each element (starts at 1 and not 0). Given that the loop also fails to complete if someArray contains a falsy value, I'd say this trick falls into the "too cute to be safe" category.
- shaboon 13y agoif that's was it's first name it should be renamed back to LiveScript
- shultays 13y ago"if you're used to math in C or Java. Watch out for stuff like: 0.1 + 0.2 == 0.30000000000000004" Uh, how floating poing operators are different than this in C or java
- brofser 13y agoI've read this article a couple of times in the last few years and it never ceases to amaze me. Clearly and in a concise way it lists all the points that people usually miss about JS.
- almog 13y ago"We've introduced another keyword: 'new'. new is strongly related to 'this'. What it does is it creates a brand new empty object, and then calls the function specified, with 'this' set to that new object" Perhaps it would be worth to mention that 'new' not only sets 'this' to be the empty object but also return that object to the location where new was used.