Skip to content Skip to sidebar Skip to footer

Prototype Property Of Class Methods In JavaScript

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 th

Solution 1:

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.


Post a Comment for "Prototype Property Of Class Methods In JavaScript"