From 6c4e9b27d2e97039116027ca15d5149e89d6b177 Mon Sep 17 00:00:00 2001 From: jasmine-dean Date: Wed, 9 Oct 2019 16:43:40 -0700 Subject: [PATCH 1/2] I completed the this.js section of the project and now I'm going to work on protypes --- README.md | 10 ++++---- assignments/this.js | 61 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ed9a277bc..d04f86481 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ This challenge focuses on using the `this` keyword as well as getting comfortabl **Follow these steps to set up and work on your project:** -* [ ] Create a forked copy of this project. -* [ ] Add your project manager as collaborator on Github. -* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!). -* [ ] Create a new branch: git checkout -b ``. -* [ ] Implement the project on your newly created `` branch, committing changes regularly. +* [x] Create a forked copy of this project. +* [x] Add your project manager as collaborator on Github. +* [x] Clone your OWN version of the repository (Not Lambda's by mistake!). +* [x] Create a new branch: git checkout -b ``. +* [x] Implement the project on your newly created `` branch, committing changes regularly. * [ ] Push commits: git push origin ``. **Follow these steps for completing your project.** diff --git a/assignments/this.js b/assignments/this.js index 969bbeeba..dabd52226 100644 --- a/assignments/this.js +++ b/assignments/this.js @@ -1,15 +1,20 @@ -/* The for principles of "this"; -* in your own words. explain the four principle for the "this" keyword below. -* -* 1. -* 2. -* 3. -* 4. -* -* write out a code example of each explanation above -*/ + // The for principles of "this"; +// in your own words. explain the four principle for the "this" keyword below. + +// 1. Window Global object binding +// Window binding is like the forest of trees, not sure which one we are pointing at so we are just pointing at the forest. +// 2. Implicit Binding + // Implicit binding means that we are pointing out a specific tree in our forest by saying "that tree" +// 3. New Binding + // New binding creates a new fucntion that says to plant that new tree over there by using the "new" example within the code + +// 4. Explicit Binding +// This says I want to go plant a new tree over there. + +// write out a code example of each explanation above // Principle 1 +console.log(this) // code example for Window Binding @@ -17,10 +22,40 @@ // code example for Implicit Binding +const person = { + name: "Jasmine", + age: "26", + location: "San Francisco", + code: function() { + return `${this.name} loves to ${this.code}`; + }} +console.log(person.code()); // Principle 3 -// code example for New Binding +//New Binding Example + +function CordialPerson(greeter) { + this.greeting = "Hola, Como estas"; + this.greeter = greeter; + this.speak = function() { + console.log( `${this.greeting} ${this.greeter} `); + } +} + +const jasmine = new CordialPerson("Jennifer Lopez"); + +jasmine.speak(); + +// Exlicit binding + +const singer = { + 'name':'Beyonce', + 'age':38 +} +const talents = ['singing','dancing', 'acting']; -// Principle 4 +function introduce() { + console.log(`My name is: ${this.name} my talents are, ${talents}`); +} -// code example for Explicit Binding \ No newline at end of file +introduce.call(singer, talents); \ No newline at end of file From b8acf86fe9e9d07d603abf65cd3a10628389e9c4 Mon Sep 17 00:00:00 2001 From: jasmine-dean Date: Thu, 10 Oct 2019 19:12:45 -0700 Subject: [PATCH 2/2] fixed the anwers about the differnet types of binding. I studied each and gave examples to show understanding --- README.md | 6 +++--- assignments/this.js | 17 +++++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d04f86481..7c9746af2 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ This challenge focuses on using the `this` keyword as well as getting comfortabl **Follow these steps for completing your project.** -* [ ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** -* [ ] Add your project manager as a reviewer on the pull-request -* [ ] Your project manager will count the project as complete by merging the branch back into master. +* [x] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** +* [x] Add your project manager as a reviewer on the pull-request +* [x] Your project manager will count the project as complete by merging the branch back into master. ## Assignment Set Up diff --git a/assignments/this.js b/assignments/this.js index dabd52226..effc1045f 100644 --- a/assignments/this.js +++ b/assignments/this.js @@ -1,15 +1,20 @@ // The for principles of "this"; // in your own words. explain the four principle for the "this" keyword below. -// 1. Window Global object binding -// Window binding is like the forest of trees, not sure which one we are pointing at so we are just pointing at the forest. +// // 1. Window Global object binding +// When you are inside of the global scope, the value of this is the entire window/console Object. It's a broad area that will need some specification. We can specify what we are implitmenting or pointignt o by using something referred to as "Implicit Binding" // 2. Implicit Binding - // Implicit binding means that we are pointing out a specific tree in our forest by saying "that tree" -// 3. New Binding - // New binding creates a new fucntion that says to plant that new tree over there by using the "new" example within the code +// Implicit binding is pointing to something directly inside of the global scope. We can specify what that is exactly by using "this." for example we can say "this.greeing" "this.age" "this.animal" +// // 3. New Binding +// New binding is when we use the new keyword to call a fucntion that creates an object for us. An example is +// fucntion CordialPerson(greeter) and then using... +// Const jasmine = new CordialPerson('tyler') +// jasmine.speak (); + // 4. Explicit Binding -// This says I want to go plant a new tree over there. +// Explicit binding is when we call someting explicitly with a new constext using .call and .apply +// an example of this is jasmine.speak.call(tyler);tyler.speak.apply(jasmine); // write out a code example of each explanation above