good coders code, great reuse |
| Posted: 27 Feb 2009 10:12 PM PST
This lecture is given by JavaScript guru Doug Crockford. He’s the author of JSON data exchange format, JSMin JavaScript minifier and JSLint. The talk is based on Douglas’s recent book “JavaScript: The Good Parts“. It’s excellent. The lecture begins with a brief intro of why JavaScript is the way it is and how it came to be so. An interesting point Doug makes is that JavaScript is basically Scheme, except with Java syntax. He talks about the bad and good parts of JavaScript and gives a few examples of common JavaScript problems, their solutions and patterns. Douglas also talks about how he discovered JSON. After the talk there is a 13 minute Q and A. You’re welcome to watch the video lecture. It’s 1 hour long and it will definitely make your understanding of JavaScript better: Direct URL: http://www.youtube.com/watch?v=hQVTIJBZook Here are some interesting points from the lecture: [09:57] JavaScript was influenced by Scheme, Java and Perl. From Scheme it borrowed lambda functions and loose typing. From Java it took most of the syntax, and from Perl some of its regular expressions. And finally, it derived the idea of prototypal inheritance and dynamic objects from Self. See my previous post on JavaScript for explanation of prototypal inheritance. [11:38] JavaScript bad parts:
[17:25] for … in operator mixes inherited functions with the desired data members (it does deep reflection). Use object.hasOwnProperty to filter out names that belong to object itself: for (name in object) { if (object.hasOwnProperty(name)) { ... } } [22:00] Javascript good parts:
[23:00] Two schools of inheritance - classical and prototypal. Prototypal inheritance means that objects can inherit properties directly from other objects. The language is class-free. [24:35] Realization of prototypal inheritance in JavaScript: if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; } Now a newObject can be created by inheriting from oldObject: newObject = Object.create(oldObject); [26:05] Example of global variables and why they are bad and how to solve the problem by using closures. var my_thing = function () { var names = ["zero", "one", ... ]; return function(n) { return names[n]; }; }(); [29:00] There are four ways to create a new object in JavaScript:
[42:42] JSLint. JSLint defines a professional subset of JavaScript. JSLint will hurt your feelings. [52:00] Q/A: Does strict mode change the behavior or does it take things out? — Can’t have “with” in strict mode, changes the way eval() works, changes error handling. [53:00] Q/A: What’s going on with DOM? — Ajax libraries fix DOM, these changes should be propagated back into DOM API. [55:30] Q/A: How do you spell lambda in JavaScript? — function. [55:54] Q/A: How to solve global variable problem? — Each of compilation unit should be isolated, but there should be a way how they can introduce (link) to each other. [56:30] Q/A: How do JavaScript objects differ from hash tables, they seem the same to me? [57:23] Q/A: What’s wrong with HTML 5 and web apps? — They are doing too much and there are way too many of them. [59:10] Q/A: How come JSON and JavaScript have almost the same syntax? — Doug admits he forgot to include Unicode Line Separator (LS) and Paragraph Separator (PS) control codes as whitespace chars. [01:00:32] Q/A: Why does JSON require quotes around the property names? — Three reasons: 1. Wanted to align with Python where quotes are required, 2. Wanted to make the grammar of standard simpler, 3. JavaScript has stupid reserved word policy. [01:02:40] Q/A: Are there any prospects for adding concurrency to the language? — Definitely no threads. Could be some kind of a messaging model. If you liked this talk, I recommend that you get Doug’s book: Happy javascripting! |
| You are subscribed to email updates from good coders code, great reuse To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
| Inbox too full? | |
| If you prefer to unsubscribe via postal mail, write to: good coders code, great reuse, c/o Google, 20 W Kinzie, Chicago IL USA 60610 | |
No comments:
Post a Comment
Keep a civil tongue.