Od zera do JavaScript developera #4
Michal Staskiewicz
https://miksturait.slack.com/
http://bit.ly/miksturait
Agenda
- Values, Types, and Operators
- Functions &Data Structures - Objects and Arrays
- Higher-order Functions
- Objects & first project
- Bugs, Errors & Regular Expression
- Modules & Asynchronous Programming
- Project - A Programming Language (review)
- Exercises - katas
Snack Challenge Review
@Marcin
@kajetanboruta
@GrzesiekG
@Malwina
@JakubM
@Dadii
@AndKaw
@Adrian
Code will be at GH (probably) today at night
Encapsulation
OOP
.call() and 'this'
function speak(line) {
console.log(`The ${this.type} rabbit says '${line}'`);
}
let whiteRabbit = {type: "white", speak};
let hungryRabbit = {type: "hungry", speak};
whiteRabbit.speak("Oh my ears and whiskers, " +
"how late it's getting!");
// → The white rabbit says 'Oh my ears and whiskers, how
// late it's getting!'
hungryRabbit.speak("I could use a carrot right now.");
// → The hungry rabbit says 'I could use a carrot right now.'
Prototypes
Symbols
let sym = Symbol("name");
Classes
class Rabbit {
constructor(type) {
this.type = type;
}
speak(line) {
console.log(`The ${this.type} rabbit says '${line}'`);
}
}
First Project!
Visual Studio Code
Game of Life
Create GameOfLife class
It should take one parameter(array) which determinate live cells and store it under cells property and size which determinate grid size (eg. 10 -> 10 x 10 cells)
Create method that setup grid based on size every cell should looks like
{ alive: false }
Create method that will setup initial cells from constructor to grid state
Create method for printing actual grid state
chars: 9634, 9632
Create the method calculates alive neighbours for given cell
Create method that will updates grid to the next epochs based on neighbours
Create method that will calculate next epoch every 1 second
Snack Challenge
Deadline - Środa 11.07 18:00
Exercises from this topic
Thanks! =>
Od zera do JavaScript developera #4
By Michał Staśkiewicz
Od zera do JavaScript developera #4
- 856