Objects, Functions and Inheritance...

What am I up to?

The web is a great target platform

They understand layout (mostly)

So I've been slinging JavaScript

This talk

Who's responsible

* Totally unsubstantiated claim.

Let's play


Objects, Functions, Inheritance

Object Creation

* I am going to retract this statement in about 10 slides...

Objects are Dictionaries

Functions

Functions and Objects

Implement Mixins

Some language features are better than others.

OK OK but let's use them as objects already


Hint: It's gonna get rough

It Just Works!

Function invocation and the magic "this" pointer

* Totally unsubstantiated claim.

Mistake: "this" to global

Fix it with a feature

apply and call

Inheritance


Oh boy, oh boy, oh boy!

An issue from before:

Hide it in the scope?

"Fake" private variables!

duck typing

but we do care about

Prototypal inheritance

Prototypal inheritance

Prototypal inheritance

everything is broken!

still broken!

Constructor Functions

The intent is not bad:

4th Function invocation:

Each function carries a prototype object with it, and when new() gets called, the created object's __proto__ points to this. Thus...

Constructor sets __proto__

Let's try inheritance

WHAT THE FUCK? SO WHY DO WE EVEN HAVE CONSTRUCTOR FUNCTIONS?! you guys REALLY SHOT YOURSELF IN THE FOOT WITH THIS ONE!

pseudoclassical

alternatives?

Can we fix this?

Remember mixins?

Still kinda sucks

options?

My way

* makes it easy to decide where code should live (Classes, not duplicated)

my way

One ugly part left :-(

how?

cool huh? not yet!

Recap

ECMAScript 6

 

 

Thank you!

github.com/njoubert/inheritance.js