I Don’t Use JavaScript Classes At All. Am I Missing Out on Something?

functionA(functionB(value))
function flowerColour(flowerType, colour) {
return `${flowerType} are ${colour}`
}
/* Call `flowerColour` partially, setting the
`flowerType` argument to "Roses" */
const rosesAre = flowerColour.bind(null, "Roses")
console.log(rosesAre("red")) // Returns "Roses are red"
/* Map is a higher-order function, because
it takes a function as an argument */
// Returns [10, 16, 37, 9]
[20, 32, 74, 18].map(number => number / 2)
/* Another higher order function, in this
case, it returns a function */
function createLuckyNumber(name) {
const luckyNumber = parseInt(10000 * Math.random())
return function() {
return `${name}'s lucky number is ${luckyNumber}`
}
}
const emmasLuckyNumber = createLuckyNumber("Emma")
const joesLuckyNumber = createLuckyNumber("Joe")
// Returns "Emma's lucky number is 7280"
console.log(emmasLuckyNumber())
// Returns "Joe's lucky number is 2971"
console.log(joesLuckyNumber())

What Make Classes Tick

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store