Skip to content

Instantly share code, notes, and snippets.

View kristyburge's full-sized avatar

Kristy Burge kristyburge

View GitHub Profile
<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 -->
@kristyburge
kristyburge / nested-objects.js
Last active August 1, 2018 14:17
Nested Objects Example
var obj1 = {
hello: function() {
console.log('Hello world');
return this;
},
obj2: {
breed: 'dog',
speak: function(){
console.log('woof!');
return this;
@kristyburge
kristyburge / window.js
Created July 27, 2018 23:10
When 'this' points to the Window object
console.log(this);
// returns the Window object
// Window { postMessage: ƒ,
// blur: ƒ,
// focus: ƒ,
// close: ƒ,
// frames: Window, …}
function myFunction() {
@kristyburge
kristyburge / arrow-this.js
Created July 27, 2018 23:11
Arrow functions example
var objReg = {
hello: function() {
return this;
}
};
var objArrow = {
hello: () => this
};
@kristyburge
kristyburge / dog.js
Last active July 27, 2018 23:33
Create a object type with a constructor function and see 'this' in action
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;
};
}
@kristyburge
kristyburge / beagles-chase.js
Created July 30, 2018 16:49
Using a function and assigning it to an object
var dog = {
breed: 'Beagles',
lovesToChase: 'rabbits'
};
function chase() {
console.log(this.breed + ' loves chasing ' + this.lovesToChase + '.');
// console.log(this);
}
@kristyburge
kristyburge / this-example.js
Created July 30, 2018 18:04
When 'this' is used inside an object, it points to the object itself
var dog = {
name: 'Chester',
breed: 'beagle',
intro: function(){
console.log(this);
}
};
dog.intro();
@kristyburge
kristyburge / test.js
Created July 30, 2018 18:05
When 'this' is used in a normal function context
function test() {
console.log('hello world');
console.log(this);
}
test();
// hello world
// Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …}
@kristyburge
kristyburge / test-strict.js
Created July 30, 2018 18:06
Strict mode and This
function test() {
'use strict';
return this;
}
console.log( test() );
// returns undefined, not the Window object … interesting
@kristyburge
kristyburge / new.js
Last active August 1, 2018 20:47
Using the new keyword
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.
*******/