A Brief History of JavaScript
Objects
literals
› o = {prop: val, ...}
properties
› get: x = o.p
› set, add: o.p = e
› delete: delete o.p
prototypes
› lookup along chain
> point = {x: 1, y: 2} Object 1. x: 1 2. y: 2 3. __proto__: Object > point.x 1 > point.z undefined > point.z = 3 3 > point.z 3 > delete point.z true > point.z undefined
> var Point = function (x, y) {this.x = x; this.y = y;} undefined > Point.prototype.magnitude = function () {return Math.sqrt(this.x * this.x + this.y * this.y);} function () {return Math.sqrt(this.x * this.x + this.y * this.y);} > p = new Point(1,2) Point > p.x 1 > p.magnitude function () {return Math.sqrt(this.x * this.x + this.y * this.y);} > p.magnitude() 2.23606797749979