Ben Aston Ben Aston -4 years ago 61
Javascript Question

prototype property of class methods in JavaScript

class C { foo() {} } // function foo() {} // undefined - why?

Why is the
property of class methods not set when created via the class method syntax?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download