Is there a way to achieve the following scenario?
console.log(a, typeof a); // prints "3 'number'"
console.log(typeof a.mymethod()); // prints 'foobar'
In non-strict mode this can be done (at least in Node), but strict mode in ECMAScript 2015 prohibits setting properties on primitive values (source).
Can I simulate this behavior using Proxy
, property descriptors, or any other technique?