1. The document summarizes JavaScript concepts like objects, data types, constructors, prototypes and inheritance.
2. It explains that in JavaScript, objects are collections of key-value pairs known as hashes, and that arrays are also objects.
3. The document also discusses how inheritance is achieved in JavaScript through prototypes - an internal property of functions that is used to provide methods and properties to objects created with a constructor.
12. Arrays Arrays are objects too Auto-increment properties Some useful methods
13. Arrays >>> var a = [1,3,2]; >>> a[0] 1 >>> typeof a "object" >>> var b = []; >>> b.push("value"); >>> console.log(b); // "value"
15. Constructor Is called at the moment of instantiation In JavaScript, the function serves as the constructor of the object var Person = function () { alert('Person instantiated'); } var person1 = new Person(); var person2 = new Person();
16. constructor property >>> function Person(){}; >>> var mony = new Person(); >>> mony. constructor === Person true
20. Inheritance A method to create a class as a specialized version of one or more classes JavaScript only supports single class inheritance
21. // define the Person Class function Person() {} Person.prototype.walk = function(){}; Person.prototype.sayHello = function(){ alert ('hello'); }; // define the Student class inherit Person function Student() {} Student.prototype = new Person(); Student.prototype.constructor = Student; // override the sayHello method Student.prototype.sayHello = function(){ alert('hi, I am a student'); }; var student1 = new Student(); student1.sayHello();
22. Prototype is a property of the function objects >>> var boo = function (){}; >>> typeof boo. prototype "object"
23. Use of the prototype The prototype is used when a function is called as a constructor
24. Prototype usage var Person = function (name) { this .name = name; }; Person. prototype .say = function (){ return this .name; };
25. Prototype usage >>> var dude = new Person( 'dude' ); >>> dude.name; "dude" >>> dude.say(); "dude"
26. Prototype usage say() is a property of the prototype object but it behaves as if it's a property of the dude object
27. Own properties vs. prototypes >>> dude. hasOwnProperty ( 'name' ); true >>> dude. hasOwnProperty ( 'say' ); false
35. Objects Everything is an object (except a few primitive types) Objects are hashes Arrays are objects Class no such thing in JavaScript A function meant to be called with new Returns an object Inheritance Support singular inheritance Prototype Property of the function objects Its an object Useful with Constructor functions
36. References Object-Oriented JavaScript, Stoyan Stefanov Pro JavaScript Techniques, John Resig https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript