Online Mind Mapping and Brainstorming

Create your own awesome maps

Online Mind Mapping and Brainstorming

Even on the go

with our free apps for iPhone, iPad and Android

Get Started

Already have an account? Log In

JacaScript patterns talk, Zohar Arad by Mind Map: JacaScript patterns talk, Zohar Arad
5.0 stars - 1 reviews range from 0 to 5

JacaScript patterns talk, Zohar Arad



We don't need inheritance chain to borrow methods from objects

We can run object methods in different scopes

Mixins are way to do this, But we don't want to dirty JS namespace

Motivation, Native JS objects have useful methods, We can emulate desired methods using native methods, More expressive & shorter code


[], Get last char of a string, Works because both array& string have length method, You can apply array methods on Everything having a length method

"".trim.apply([" a", "b "]).split(",")





Forcing OOP patterns on JS is wrong, It's power lies in prototypes

Zohar stopped using OO, After noticing that besides extending MooTools classes, there's usually nothing in his classes

Why mixins?, Code reuse, Modularity, Avoiding inheritance chain, Readability, Maintainability

Ruby has extremely useful notion, Extend, Add functionality to class, Include, Add functionality to instance

Example, See fiddle link in slides, Zohar's version is my modified version of Osmani's version, extend & include methods, Logger mixin, Added to instance


Why, Working synchronously in JS sucks, Hard-coded API, Easier to break, Less expressive

JS has a notion of events, lets use it, Instead of defining API we define messages, Action handling is encapsulated& distributed, Logic of handling is encapsulatedat the component listening to the event, Nice example is handling google Analytics events, Decoupling, No missing methods errors, More expressive code, Problems, We need to design our channels carefully, Avoid callback spaghetti, There's no delivery guarantee

See fiddle example in slides, subscribe to topic method, Returns token for easy unsubscribe, Publish method, To topic, Unsubscribe, Problem, All subscribers receive drive events, Try avoid subscribers spaghetti, Error in callback will stop event handling - add try/catch around callback


Addi Osmani has a book & site with many patterns

There are many


Not the Java OOP patterns