class C { foo() {} }
C.prototype.foo // function foo() {}
C.prototype.foo.prototype // undefined - why?
Why is the .prototype
property of class methods not set when created via the class method syntax?
class C { foo() {} }
C.prototype.foo // function foo() {}
C.prototype.foo.prototype // undefined - why?
Why is the .prototype
property of class methods not set when created via the class method syntax?
Because methods (like arrow functions) are no constructors, and don't need a .prototype
from which the prototype of instances would be initialised, none will get created.
This is a new feature in ES6, which distinguishes method definitions in object literals and class
definitions from usual function
definitions.