Function-prototype-toString-revision icon indicating copy to clipboard operation
Function-prototype-toString-revision copied to clipboard

Include static keyword in method toString

Open jridgewell opened this issue 7 years ago • 2 comments

Static is currently excluded from a method's toString:

class Ex {
  static test() { /* hello */ }
}

console.log(Ex.test.toString());
// => 'test() { /* hello */ }'

The decorators group would like to include it in the toString, since it can't go before the decorators.

jridgewell avatar Aug 21 '18 18:08 jridgewell

Even unrelated to decorators, it makes sense, and follows the mental model, that if you eval Ex.test.toString() inside a similar lexical context (the body of class Ex, with the same variable bindings in scope) that it should result in a static method.

ljharb avatar Aug 21 '18 20:08 ljharb

Intutiively, I like this change. To me, it seems like static is part of the method declaration just as much as async is. I don't think we should put too much stock into the details of a particular version of the spec's grammar when making these sorts of decisions.

littledan avatar Sep 12 '18 05:09 littledan