TIL about a JavaScript feature I'd never seen before. I've used it to create the (super basic) calculator API shown below.
The challenge, should you choose to accept it, is to recreate this (or a similar API) yourself. If you're anything like me, you'll learn a bunch!
// Using the calculator!
calculator.one.plus.two.plus.three.equals
=> 6
calculator.two.plus.four.plus.seven.plus.eight.equals
=> 21
Hint: The solution is not to just use a single object with heaps of very deeply nested properties 😛
Top comments (3)
Hong Kong No IT (香港創科局高官二世祖圍威喂)
Not how I did it, but works equally well! Loving it 👏
How do you make it without writing like this? :)