Exercise 1: Revocable Proxy

Practice your revocable proxy skills by completing this exercise.

Problem statement

Implement the createRevocableProxy() method in the following code to create a proxy that can be used for up to 3 seconds. During that time, any method calls on the proxy should be directed to the target instance.

Sample input and output

The sample input calls and their respective outputs are given in the table below.

Input Output
callGetYear(); current year
setTimeout(callGetYear, 1000); current year
setTimeout(callGetYear, 5000); Cannot perform ‘get’ on a proxy that has been revoked

Exercise

Solve this challenge to practice proxies. The solution to this exercise is available in the next lesson, but try to solve it yourself first.

Get hands-on with 1200+ tech skills courses.