This document summarizes some key aspects of JavaScript including:
- JavaScript's basic language features like functions, objects, and exceptions.
- The good parts of JavaScript like first-class functions, object literals, closures, and prototyping which enable powerful programming patterns.
- The bad parts like inconsistent cross-browser support, eval(), tricky truthiness rules, and missing declarations which can cause bugs.
- That following good coding practices, using common sense, and static analysis can help address JavaScript's weaknesses.
22. class Counter {
private int x = 0;
public void count() {
return x++;
}
}
var c1 = new Counter();
var c2 = new Counter();
var a = [c1.count(),
c1.count(),
c2.count()];
alert(a);
23. function counter() {
var x = 0;
var f = function() {
return x++;
}
return f;
}
var c1 = counter();
var c2 = counter();
var a = [c1(), c1(), c2()];
alert(a);
24. • C lets us forget stacks, heaps and jumps
• Java lets us forget memory management
• JavaScript lets us forget creating state
26. function Animal(name) {
this.name = name;
this.talk = function() {
alert(this.name + ”: huh?”);
}
}
var a = new Animal(”garfield”);
var b = new Animal(”lassie”);
alert(a.name);
alert(b.talk());
27. function Animal(name) {
this.name = name;
}
Animal.prototype.talk = f() {
alert(this.name + ”: huh?”);
}
var a = new Animal(”garfield”);
var b = new Animal(”lassie”);
alert(a.name);
alert(b.talk());