a programming paradigm
a code style
a mindset
a sexy, buzz-wordy trend
object-oriented JS gets tricky(prototypes? this?!?)
safer, easier to debug/maintain
established community
input → output
var name = “Anjana”;
var greeting = “Hi, I’m ”;
console.log(greeting + name);
> “Hi, I’m Anjana”
function greet(name) {
return “Hi, I’m ” + name;
}
greet(“Anjana”);
> “Hi, I’m Anjana”
- use
pure
functions
var name = 'Foyez'
function greet() {
console.log("Hi, I'm " + name)
}
function greet(name) {
return "Hi, I'm " + name
}
functions can be inputs/outputs
function makeAdjectifier(adjective) {
return function (string) {
return adjective + “ ” + string;
};
}
var coolifier = makeAdjectifier(“cool”);
coolifier(“conference”);
> “cool conference”
use map, reduce, filter
use immutable data
var rooms = [“H1”, “H2”, “H3”];
rooms[2] = “H4”;
// rooms => ["H1", "H2", "H4"]
var rooms = [“H1”, “H2”, “H3”];
var newRooms = rooms.map(rm => rm === "H3" ? "H4" : rm);
// newRooms => ["H1", "H2", "H4"]
// rooms => ["H1", "H2", "H3"]
libraries
: Mori, Immutable.js
- Mori (http://swannodette.github.io/mori)
- Immutable.js (https://facebook.github.io/immutable-js/)
- Underscore (http://underscorejs.org)
- Lodash (https://lodash.com)
- Ramda (http://ramdajs.com)