Exercise on Proxies
Using your knowledge of proxies object, you must use them to: i) log the number of times a function is accessed ii) create a revocable discount object
We'll cover the following...
We'll cover the following...
Exercise 1:
Suppose the following fibonacci implementation is given:
fibonacci = n =>
n <= 1 ? n :
fibonacci( n - 1 ) + fibonacci( n - 2 );
Determine how many times the fibonacci function is called when evaluating fibonacci( 12 ).
Determine how many times fibonacci is called with the argument 2 when evaluating fibonacci( 12 ).
Explanation:
The solution is not that hard. As we learned earlier,
fibonacci = new Proxy( fibonacci, { uses the same reference name as our fibonacci function so that the proxy can be applied on all recursive calls as well.
Within the proxy, we increment ...