is an excellent book by Douglas Crockford (isbn 978-0-596-51774-8). As usual I'm going to quote from a few pages:
This is not a book for beginners... This book is small but it is dense. There is a lot of material packed into it. Don't be discouraged if it takes multiple readings to get it. Your efforts will be rewarded.
JavaScript's popularity is almost completely independent of its qualities as a programming language.
JavaScript is the first lambda language to go mainstream. Deep down, JavaScript has more in common with Lisp and Scheme than with Java.
strong typing does not eliminate the need for careful testing.
despite its deficiencies, JavaScript is really good.
Unlike many other languages, blocks in JavaScript do not create a new scope, so variables should be defined at the top of the function, not in blocks.
An object is a container of properties, where a property has a name and a value. A property name can be any string, including the empty string. A property value can be any JavaScript value except for undefined.
An inner function also enjoys access to the parameters and variables of the functions it is nested within... This is called closure. This is the source of enormous expressive power.
That act of nothingness gives us confidence that the function does not recurse forever.
What matters about an object is what it can do, not what it is descended from.
JavaScript provides a much richer set of code reuse patterns.
Much of the complexity of class hierarchies is motivated by the constraints of static type checking.
var memoizer = function(memo, formula) {
var recur = function(n) {
var result = memo[n];
if (typeof result !== 'number') {
result = formula(recur, n);
memo[n] = result;
}
return result;
};
return recur;
};
var fibonacci = memoizer([0, 1], function(recur, n) {
return recur(n - 1) + recur(n - 2);
});
No comments:
Post a Comment