Hacker News new | past | comments | ask | show | jobs | submit login

i've used this in the past:

  function isClass(fn) {
    return !Object.getOwnPropertyDescriptor(fn, 'prototype').writable;
  }
it relies on the fact that the prototype object of ES6 classes always non-writable.



Note that this breaks with Babel and TypeScript, since I guess this is one aspect where neither strictly follows the spec. Both of these examples print false:

https://babeljs.io/repl/build/master/#?babili=false&browsers...

https://www.typescriptlang.org/play/index.html#src=function%...


I don't think that would work for the standard es5 pattern of using functions as classes?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: