I am an experienced object oriented programmer but this got me! Why am I able to do new f() but not new a(). I will appreciate any pointers.
// first a few fa
As the error points out, a
is expected to be a function, that is, it must be callable. The new
keyword requires a function object that knows how to construct an instance - but a
does not. Letting it inherit from Function.prototype
(by using __proto__
) does not help anything, callability is an intrinsic property of objects.
You are able to call new f()
, as f
is such a constructor function, being created by the Function constructor.