This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function a( ) { | |
| var myvar = 2 | |
| function b() { | |
| console.log(myvar); | |
| } | |
| b( ); | |
| } | |
| var myvar = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Let's assume we have object o, with its own properties a and b: | |
| // {a: 1, b: 2} | |
| // o.[[Prototype]] has properties b and c: | |
| // {b: 3, c: 4} | |
| // Finally, o.[[Prototype]].[[Prototype]] is null. | |
| // This is the end of the prototype chain as null, | |
| // by definition, null has no [[Prototype]]. | |
| // Thus, the full prototype chain looks like: | |
| // {a:1, b:2} ---> {b:3, c:4} ---> null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var o = { | |
| a: 2, | |
| m: function(b){ | |
| return this.a + 1; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var o = { | |
| a: 2, | |
| m: function(b){ | |
| return this.a + 1; | |
| } | |
| }; | |
| console.log(o.m()); // 3 | |
| // When calling o.m in this case, 'this' refers to o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = ["yo", "whadup", "?"]; | |
| // Arrays inherit from Array.prototype | |
| // (which has methods like indexOf, forEach, etc.) | |
| // The prototype chain looks like: | |
| // a ---> Array.prototype ---> Object.prototype ---> null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function greet() { | |
| console.log('hi') | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function greet() { | |
| console.log('hi') | |
| } | |
| greet.language = 'english' | |
| console.log(greet.language) | |
| // => 'english' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person { | |
| constructor(firstname, lastname) { | |
| this.firstname = firstname; | |
| this.lastname = lastname; | |
| } | |
| greet () { | |
| return 'hi ' + firstname; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class InformalPerson extends Person { | |
| constructor(firstname, lastname) { | |
| super(firstname, lastname); | |
| } | |
| greet () { | |
| return 'Yo ' + firstname; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var john = new Person(); | |
| function Person() { | |
| this.firstname = ‘John’ | |
| this.lastname = ‘Doe’ | |
| } |