Infinite Method Object - Problem

Write a function that returns an infinite-method object. An infinite-method object is defined as an object that allows you to call any method name and it will always return the name of that method as a string.

For example, if you execute obj.abc123(), it should return "abc123". If you call obj.hello().world().foo(), each method call should return its respective method name.

Key Requirements:

  • The object should support calling any method name
  • Each method call returns the method name as a string
  • Method chaining should work (each method returns an object that also supports infinite methods)

Input & Output

Example 1 — Basic Method Call
$ Input: obj = solution(); obj.abc123()
Output: "abc123"
💡 Note: The method abc123 is called on the infinite-method object, which returns the string 'abc123'
Example 2 — Different Method Name
$ Input: obj = solution(); obj.hello()
Output: "hello"
💡 Note: Any method name works - calling hello() returns the string 'hello'
Example 3 — Complex Method Name
$ Input: obj = solution(); obj.test123WithNumbers()
Output: "test123WithNumbers"
💡 Note: Even complex method names with numbers and camelCase work perfectly

Constraints

  • Method names follow JavaScript identifier rules
  • Method names can contain letters, numbers, underscore, and dollar sign
  • Method names cannot start with a number

Visualization

Tap to expand
Infinite Method Object: Any Method → Method Namesolution()creates objectobj.abc123()obj.hello()obj.test123()obj.anyMethod()"abc123""hello""test123""anyMethod"Pattern: obj.methodName() → "methodName"Works for ANY method name - truly infinite!
Understanding the Visualization
1
Input
Create infinite-method object using solution()
2
Method Calls
Call any method name on the object
3
Output
Each method returns its name as a string
Key Takeaway
🎯 Key Insight: JavaScript Proxy intercepts property access to create truly infinite method support
Asked in
Google 15 Facebook 12 Microsoft 8
29.4K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen