Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Global - context Window (not used just a heads up)
* 2. Implicit - bound to object (left of the . automatic)
* 3. New - When ever a constructor is used (use the new statement )
* 4. Explicit - When using .call and .apply or .bind
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding

console.log(this);
// Principle 2
// const bubble = {
// type: "Large",
// color: "irredecent",
// blower: "Fred"

// };



// code example for Implicit Binding

// Principle 3

const bubbleBlower = {
name: function(name) {
console.log(`A ${this.size} ${this.color} Bubble was blown by ${name}`)
},
size: "Large",
color: "Green"
};
bubbleBlower.name('Nancy');
// code example for New Binding

function Bubbles(name, size, color) {
this.color = color;
this.size = size;
this.name = name;
this.blow = function() {
console.log(`${this.name} blew a ${size} ${color} bubble.`);
}
};
// Principle 4

// expllicit
// code example for Explicit Binding