Skip to content

Instantly share code, notes, and snippets.

View chadfurman's full-sized avatar

Chad Furman chadfurman

View GitHub Profile
@chadfurman
chadfurman / notes7.md
Last active February 10, 2017 13:20
Notes7
  • Callback Hell -- indentation isn't the problem. The problem is about losing control of the invocation of your code.
  • The "inversion of control" from callback hell is the problem.
  • Generators were great to learn about. It's much clearer now.
  • Generators are an old thing in computer science. Neat to know they're also in JS
  • Yield and .next() make much more sense now :)
  • Where would we use Generators, though?
  • Using promises and generators together is something new! That's interesting...
  • ES7 async functions might make the interaction much nicer
  • Promises are good not only because they're cleaner, but because they solve the IoC problem
  • We have been using promises in our code quite a bit. The explanation with setTimeouts was nice
@chadfurman
chadfurman / h7.md
Last active February 10, 2017 08:53
h7

Callbacks

  • Agenda
    • Async Patterns (i.e. Callbacks)
    • Generators / Coroutines
    • Promises
setTimeout(function(){
  console.log("callback!");
}, 1000);
@chadfurman
chadfurman / h6.md
Last active February 10, 2017 07:41
h6

Inheritance

  • Prototypal Inheritance is not Inheritance -- Inheritance is for class-based languages
  • Prototypal Inheritance is completely opposite of regular Inheritance
  • When we create an object with Prototypes, the new object links "up" the prototype chain.
  • In regular inheritance, we have a "parent" class and the Inheritance flows downward.
  • Inheritance is "copy down", Prototypal is "delegate up"
  • All OO in JS is an attempt to make Prototype Inheritance work like Class Inheritance
  • We should instead consider JS as having Behavior Delegation, which is a design pattern.
@chadfurman
chadfurman / notes6.md
Last active February 7, 2017 16:24
notes6
  • Classical inheritance is copies
  • Coming from a C background, it's easy to see the difference with JS's inheritance
  • Objects linked to other objects, the delegation, is interesting
  • The differences between inheritance and behavior delegation
  • Kyle's methods have some small drawbacks, but 90% of the time his pattern would be good
  • If someone wants to have the classical model of inheritance, it's less a personal choice and more a tool for the problem
  • Typescript can give us this classical pattern.
  • We use classes for models, how can we use prototypes to be very useful? Especially in a webapp?
  • using .call and calling the constructor itself vs using the new keyword
  • writing .prototype feels a little strange. It's a bit simpler to use Kyle's pattern...
@chadfurman
chadfurman / Notes5.md
Created February 3, 2017 13:10
Notes5

Prototypes

  • Prototype Links [[Prototype]]
  • proto vs .prototype
  • this being super unicorn magic
  • Singleton, Observer patterns? Anyone use?
  • It'll be good to squish our notes together into pages
  • Likewise, it will also be good to add some questions to Aurelian's tool

Prototypes

  • object oriented JS has lots of complexity -- going to try to simplify common OO patterns prototypes "Inheritance" vs "behavior delegation" "There are no Classes in JS" -- we need a different syntax & design pattern for our software "OO vs OLOO"?
var Router = function() {
  // Singleton!
@chadfurman
chadfurman / asdf
Created February 3, 2017 07:05
asdf
asdf
@chadfurman
chadfurman / notes4.md
Created January 31, 2017 13:44
Meeting Notes 4

Meeting notes

  • Module pattern is very common. Old way of wrapping with a function, new way of export/import
  • Module pattern is something many frameworks have been using for a long time.
  • A really useful pattern since in JS we don't have access modifiers
  • What about module ___ from 'module' ? I think it's actually import * as module from 'module'
  • What about multiple exports in a single file? I think this is legal
  • this keyword -- the four rules.
    • new keyword
    • explicit
  • implicit
@chadfurman
chadfurman / h4.md
Last active January 31, 2017 13:43
hour4

The new keyword

When we put the new keyword infront of any funciton call, it turns the function call into a constructor call This isn't the same as a class There are 4 things that happen when a new keyword is put infront of a function call:

  1. An empty object is created
  2. The empty object gets linked to a different object
  3. empty object gets bound as this for the purpose of the function call
  4. if the function does not otherwise return anything, new will insert return this
@chadfurman
chadfurman / h3.md
Last active January 31, 2017 04:12
Hour3

Dynamic Scope

Theoretical -- not used in JS

function foo() {
  console.log(bar); // bar is defined in baz, foo was called from baz, so bar is defined
}

function baz() {
  var bar = "bar"; // this is defined in foo because of the callstack
  foo();