handson.io


JAvascript
Functional inheritance


Alan Hortz @alanhortz
Benoît Toussaint @bantoutou

http://handsonio.github.io/js_functional_inheritance/

Reference



http://goo.gl/38HLaO                             http://goo.gl/Vc1vdv

Inheritance


"It is a form of code reuse"
"Patterns of code reuse are extremely important because they have the potential to significantly reduce the cost of software development"

- Douglas Crockford, Javascript, The good parts

"A way of obtaining code code without writing it. In particular, a subclass can inherit the implementations of its superclass's method."
- Barbara Liskov, Program Development in Java

Classical inheritance


Objects are defined by classes

Classes can inherit attributes and 
behavior from pre-existing classes

DIFFERENTIAL inheritance



Common inheritance model used by 
prototype-based programming languages

Objects are derived from others

Only differ in a few small aspects.






Functional inheritance in JS

Why bother ?


Pros


Better encapsulation


Real privacy vs Pretended privacy


Tamper-proof objects


Object composition


Cons


Performance

Put your Hands-on !


Door


Lockable Door


Delegation of the locking behavior to a WardedLock


http://handsonio.github.io/js_functional_inheritance/

HANDSON.IO / JS Functional Inheritance

By alanhortz

HANDSON.IO / JS Functional Inheritance

  • 1,301