|
1 | 1 | 
|
2 | 2 |
|
3 |
| -# Prototype |
4 |
| - |
5 |
| -This MD file serves as example/template. |
| 3 | +# Prototype |
6 | 4 |
|
7 |
| -It will be filled up soon. |
| 5 | +According to [W3schools](http://www.w3schools.com/js/js_object_prototypes.asp): |
| 6 | +Every JavaScript object has a prototype. The prototype is also an object. |
| 7 | +All JavaScript objects inherit their properties and methods from their prototype. |
8 | 8 |
|
9 |
| -(for Bucky to fill up) |
10 | 9 |
|
11 | 10 |
|
12 | 11 | # Course Documentation
|
| 12 | + |
| 13 | + |
| 14 | +## Javascript prototypes |
| 15 | + |
| 16 | +According to [W3schools](http://www.w3schools.com/js/js_object_prototypes.asp): |
| 17 | +**Every JavaScript object has a prototype. The prototype is also an object.** |
| 18 | + |
| 19 | + Person.prototype.getName = function () { |
| 20 | + return this.firstName + " " + this.lastName; |
| 21 | + }; |
| 22 | + |
| 23 | +All JavaScript objects inherit the properties and methods from their prototype. |
| 24 | +Objects created using an object literal, or with new Object(), inherit from a prototype called Object.prototype. |
| 25 | +Objects created with new Date() inherit the Date.prototype. |
| 26 | +The Object.prototype is on the top of the prototype chain. |
| 27 | +All JavaScript objects (Date, Array, RegExp, Function, ....) inherit from the Object.prototype. |
| 28 | + |
| 29 | + Person.prototype.getName = function () { |
| 30 | + return this.firstName + " " + this.lastName; |
| 31 | + }; |
| 32 | + |
| 33 | + var bucky = new Person('Bucky', 'Roberts'); |
| 34 | + var emily = new Person('Emily', 'Jones'); |
| 35 | + |
| 36 | + console.log(bucky.getName()); |
| 37 | + console.log(emily.getName()); |
| 38 | + |
| 39 | +## Objects |
| 40 | + |
| 41 | +In our example for objects we used the following code: |
| 42 | + |
| 43 | + |
| 44 | + Person.prototype.getName = function () { |
| 45 | + return this.firstName + " " + this.lastName; |
| 46 | + }; |
| 47 | + |
| 48 | + var bucky = new Person('Bucky', 'Roberts'); |
| 49 | + var emily = new Person('Emily', 'Jones'); |
| 50 | + |
| 51 | + |
| 52 | + That is the typical syntax of javascripts object as well: |
| 53 | + |
| 54 | + var objectname = { |
| 55 | + property1: "property1valueinstringformat", |
| 56 | + property2: property2valueinarithmeticformat |
| 57 | + }; |
| 58 | + |
| 59 | +We achieve to insert more values in one variable by turning it to an object and by use the "property" format to each of our value |
| 60 | + |
13 | 61 |
|
14 |
| -(this for me to fill up with every element |
| 62 | + { property: valueofproperty }; |
15 | 63 |
|
16 |
| -that you use in lessons. syntax |
| 64 | + Curley brackets are defining the are of the properties, and also they defining that our variable is an object, and we separate our properties with the comma symbol. |
17 | 65 |
|
18 |
| -explaination and links for more) |
| 66 | + - Read more about [Object Oriented |
| 67 | + Programming](https://en.wikipedia.org/wiki/Object-oriented_programming) |
| 68 | + - in Wikipedia Read more about [Javascript |
| 69 | + Objects](http://www.w3schools.com/js/js_objects.asp) in W3schools |
19 | 70 |
|
20 |
| -## Element to explain |
21 | 71 |
|
22 |
| -(for example console.log) |
23 | 72 |
|
24 |
| -***Links*** |
25 |
| - - Wikipedia |
26 |
| - - Anotherlink,com |
| 73 | +> Written with [StackEdit](https://stackedit.io/). |
0 commit comments