This file contains 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
<div class="cover"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-6 col-md-offset-6 welcome"> | |
<h2>Your title</h2> | |
<p class="lead">This text is on the right side of the page</p> | |
</div><!-- .col --> | |
</div><!-- .row --> | |
</div><!-- .container --> | |
</div><!-- .cover --> |
This file contains 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 obj1 = { | |
hello: function() { | |
console.log('Hello world'); | |
return this; | |
}, | |
obj2: { | |
breed: 'dog', | |
speak: function(){ | |
console.log('woof!'); | |
return this; |
This file contains 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
console.log(this); | |
// returns the Window object | |
// Window { postMessage: ƒ, | |
// blur: ƒ, | |
// focus: ƒ, | |
// close: ƒ, | |
// frames: Window, …} | |
function myFunction() { |
This file contains 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 objReg = { | |
hello: function() { | |
return this; | |
} | |
}; | |
var objArrow = { | |
hello: () => this | |
}; | |
This file contains 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 Dog(breed, name, friends){ | |
this.breed = breed; | |
this.name = name; | |
this.friends = friends; | |
this.intro = function() { | |
console.log(`Hi, my name is ${this.name} and I’m a ${this.breed}`); | |
return this; | |
}; | |
} |
This file contains 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 dog = { | |
breed: 'Beagles', | |
lovesToChase: 'rabbits' | |
}; | |
function chase() { | |
console.log(this.breed + ' loves chasing ' + this.lovesToChase + '.'); | |
// console.log(this); | |
} |
This file contains 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 dog = { | |
name: 'Chester', | |
breed: 'beagle', | |
intro: function(){ | |
console.log(this); | |
} | |
}; | |
dog.intro(); |
This file contains 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 test() { | |
console.log('hello world'); | |
console.log(this); | |
} | |
test(); | |
// hello world | |
// Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …} |
This file contains 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 test() { | |
'use strict'; | |
return this; | |
} | |
console.log( test() ); | |
// returns undefined, not the Window object … interesting |
This file contains 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 str = new String('Hello world'); | |
/******* | |
You could do the above, but it's best to avoid it (instead do like the variable str2 below) | |
(because JavaScript knows that anything inside single or double quotes has the type of String) | |
Same goes for other primitives. This is for example purposes only. | |
NOTE: To clarify -- the only time I ever use the new keyword in practice is when I use a function constructor and create my own object type. | |
*******/ |
OlderNewer