diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b148830 Binary files /dev/null and b/.DS_Store differ diff --git a/class1.html b/class1.html index d681249..3b3c996 100644 --- a/class1.html +++ b/class1.html @@ -1,159 +1,197 @@ -
- + + -
- Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
--
Some "rules"
-Tell us about yourself.
--
Need help?
Note the resources on the whiteboard
Thank you to our wonderful TAs!
- -We'll be using the following tools in class:
--
Edit on CodePenFork button at the topSee the Pen Block-scoping: ES5 (Before) by Liz Shaw (@anythingcodes) on CodePen.
- - -
+ Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on + instruction.
++
Some "rules"
+Tell us about yourself.
++
+ Need help?
+
Note the resources on the whiteboard
+ Thank you to our wonderful TAs! +
+ +We'll be using the following tools in class:
++
Edit on CodePen
+ Fork button at the topSee the Pen + Block-scoping: ES5 (Before) by Liz Shaw ( + @anythingcodes) on + CodePen.
+ + +📄 Standard:
-
✍ Implementation:
-
-
+
✍ Implementation:
+
- 📝 We'll implement the new features from versions 6 and 7 of ECMAScript using JavaScript -
+
+
+
+
const getMessage = () => 'Hello World';
- Waiting...
- const getMessage = () => 'Hello World';
- - +
Waiting...
+ + + + +
You can set this up on your machine using Node.js. For now, CodePen can use Babel to transpile ES6 for us.
+
+
+
function func() {
+ // function required
+}
+
+
+ var
+ only respects function scopes
+
{
+ // block is anything within { } that isn't a function or a declaration of an object
}
-
-if (isPhiladelphia) {
- var alwaysSunny = true;
-}
- { }, if () { }, for() {}, while() { }, etc.function func() {
- // function required
-}
- var only respects function scopes
alwaysSunny exists in the global scope{} does not. Any variables defined in a function remain scoped there, and aren't accessible outside.{ },
+ if () { },
+ for() {},
+ while() { }, etc.
+
+ + Function vs. Block Scope » +
+alwaysSunny exists in the global scope{} does not. Any variables defined in a function remain scoped there, and aren't accessible outside.{ }, unlike the function-scoped
+ var
+ Let
+ can be reassigned
+ Const
+ cannot be reassigned
+
+
+
Instructions can be found by editing the below pen on CodePen. Be sure to fork the pen first if you'd like to save your work to your account!
-See the Pen Block-scoping with let (Before) by Liz Shaw (@anythingcodes) on CodePen.
- View Solution -Instructions can be found by editing the below pen on CodePen. Be sure to fork the pen first if you'd like to save your + work to your account!
+See the Pen + Block-scoping by Liz Shaw ( + @anythingcodes) on + CodePen.
+ View SolutionSee the Pen + Block-scoping with let (Before) by Liz Shaw ( + @anythingcodes) on + CodePen.
+ View Solution +i in the outer scope that was closed over, instead of a new i for each iteration's function to close over.i in the outer scope that was closed over, instead of a new
+ i for each iteration's function to close over.var?window in browsers). Much safer.
+ Allow multi-line strings
-Great for use with HTML templates
-'' +
+
+ Template Strings
+ Allow multi-line strings
+ Great for use with HTML
+ templates
+
+
+
+ ES5:
+ '' +
'Hello ' + str + '!
' +
'';
- becomes
-
-
- ES6:
- `
+ becomes
+
+
+ ES6:
+ `
Hello ${str}!
`;
-
- Ask who's used the ES5 version and gotten confused about plus signs, quotation marks, etc. when adding variables
-
+
+ Ask who's used the ES5 version and gotten confused about plus signs, quotation marks, etc. when adding variables
+
+
+
+ Using Template Strings
+ const message = `User ${name} scored ${score} on the exam`;
+
+
+ - Use backticks (
+
` `) around the string
+ - Use
+
${ } around any
+ variable or
+ expression
+
+ - Work well with
+ ternary operators, for example
+
+ ${ userIsYoungerThan21 ? serveGrapeJuice() : serveWine() }
+
+
+
+ const message = `User ${name} ${score >= 60 ? 'passed' : 'failed'} the exam`;
+
+ Can't use
+ if because that's a statement, not an expression. Ternary operators are expressions.
+
+
+
+
+ Activity
+ Refactor this code to use template strings.
+
+ See the Pen
+ Template Strings Activity by Liz Shaw (
+ @anythingcodes) on
+ CodePen.
+
+ View Solution
+ Focus on the
+ html variable
+
+
+
+ Enhanced Object Literals
+ ES6 has a few minor changes to make code more understandable/easy-to-read
+
+
+
+ Property Initializer Shorthand
+ When an object property name is the same as the local variable name, you can include the name without a colon and value
+
+
+ ES5:
+ function saveData(url, data){
+ $.ajax({ method: 'POST', url: url, data: data });
+}
+ becomes
+
+
+ ES6:
+ function saveData(url, data){
+ $.ajax({ url, data, method: 'POST' });
+}
+
+
+ Sometimes referred to as
+ enhanced literal notation
+
+ Convention is to place shorthanded properties at beginning for readability. This example uses jQuery, but you don't need
+ to know it; it's just an example.
+
+
+
+ Concise methods
+ Object methods no longer need
+ : function
+
+
+
+ ES5:
+ var dog = {
+ name: 'Boo',
+ bark: function() {
+ console.log('yip!');
+ }
+};
+dog.bark(); // yip!
+ becomes
+
+
+ ES6:
+ const dog = {
+ name: 'Boo',
+ bark() {
+ console.log('yip!');
+ }
+};
+dog.bark(); // yip!
+
+
+ Reformat ES5 version in front of students
+
-
- Using Template Strings
- const message = `User ${name} scored ${score} on the exam`;
-
+
+ Activity
+ Using Enhanced Object Syntax
+
+ See the Pen
+ Object Syntax by Liz Shaw (
+ @anythingcodes) on
+ CodePen.
+
+ View Solution
+
+
+
+
+ Classes
+
+
+
+
+ Classes
+
+
+ ES5:
+ function Vehicle(type) {
+ this.type = type;
+}
+
+Vehicle.prototype.logType = function() {
+ console.log(this.type);
+};
+
+var car = new Vehicle('car');
+car.logType(); // 'car'
+
+console.log(car instanceof Vehicle); // true
+console.log(car instanceof Object); // true
+
+
+
+ ES6:
+ class Vehicle {
+ constructor(type) {
+ this.type = type;
+ }
+
+ logType() {
+ console.log(this.type);
+ }
+}
+const car = new Vehicle('car');
+car.logType(); // 'car'
+
+console.log(car instanceof Vehicle); // true
+console.log(car instanceof Object); // true
+
+
+
+
+ You don't need commas between the elements of a class
+
+ In ES5, we only had class-like structures. Involved creating a constructor and assigning methods to the constructor's
+ prototype, an approach commonly referred to as creating a custom type. Why use classes?
- - Use backticks (
` `) around the string
- - Use
${ } around any variable or expression
- - Work well with ternary operators, for example
${ userIsYoungerThan21 ? serveGrapeJuice() : serveWine() }
+ - Class declarations, unlike function declarations, are not
+ hoisted; they behave like
+
let declarations
+ - All code inside class declarations runs in strict mode automatically
+ - Calling the class constructor without
+
new throws an error
+ - Attempting to overwrite the class name within a class method throws an error
-
- const message = `User ${name} ${score >= 60 ? 'passed' : 'failed'} the exam`;
-
- Can't use if because that's a statement, not an expression. Ternary operators are expressions.
-
-
+
+
+
+
+ Derived Classes
+
+ Derived classes: Classes that inherit from other classes
+ Within the derived class's
+ class {} definition, use the
+ extends keyword to specify the base class. Then access the base class constructor by calling
+ super().
+ class Rectangle {
+ constructor(length, width) {
+ this.length = length;
+ this.width = width;
+ }
+
+ getArea() {
+ return this.length * this.width;
+ }
+}
+
+ class Square extends Rectangle {
+ constructor(length) {
+ super(length, length); // calls the base class constructor
+ }
+}
-
- Activity
- Refactor this code to use template strings.
-
- See the Pen Template Strings Activity by Liz Shaw (@anythingcodes) on CodePen.
+const square = new Square(5);
+console.log(square.getArea()); // 25
+
+
+ Inheritance -- no true object inheritance, but there is prototypal inheritance. If you ask 5 different engineers how it works,
+ you’ll get 5 different answers. This is ES6’s solution to prototypal inheritance. Whenever you use a class, under the
+ hood, you’re still using prototypal inheritance.
+
+
+
+
+ Activity
+ Classes and Derived Classes
+
+
+ Activity 1
+ See the Pen
+ Classes by Liz Shaw (
+ @anythingcodes) on
+ CodePen.
+
+ View Solution
+
- View Solution
- Focus on the html variable
-
+
+ Activity 2
+ See the Pen
+ Shop Activity - Classes and Derived Classes by Liz Shaw (
+ @anythingcodes) on
+ CodePen.
+ View Solution
+
+
+
+
+
+ Optional Activity
+ Practice Test Driven Development with http://es6katas.org/
+
-
- At-Home Challenge
- Fruit Basket
-
-
- var fruit = 'apple';
+
+ At-Home Challenge
+ Fruit Basket
+
+
+ var fruit = 'apple';
(function basket(){
var fruit = 'banana';
@@ -598,76 +1027,82 @@ Fruit Basket
fruitBasket.getFruit();
console.log(fruit);
-
-
- What would the following output to the console and why?
-
-
-
- Common interview question!
-
-
-
-
-
- Next Week
-
- - Review at-home challenge from today's class
- - Arrow Functions
- - Arrow Functions and
this
- - Array Helpers
- - Altering Arrays
-
-
-
- Remember to do the at-home challenge!
-
-
- Questions
- ?
-
+
+ What would the following output to the console and why?
- Can always email me!
-
+
+
+
+ Common interview question!
+
+
+
+
+
+ Next Week
+
+ - Review at-home challenge from today's class
+ - Arrow Functions
+ - Arrow Functions and
+
this
+
+ - Array Helpers
+ - Altering Arrays
+
+
+
+
+ Remember to do the at-home challenge!
+
+
+
+ Questions
+ ?
+
+
+ Can always email me!
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+