isConstructor.js 366 B

12345678910111213141516
  1. // Copyright (C) 2017 André Bargull. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. description: |
  5. Test if a given function is a constructor function.
  6. ---*/
  7. function isConstructor(f) {
  8. try {
  9. Reflect.construct(function(){}, [], f);
  10. } catch (e) {
  11. return false;
  12. }
  13. return true;
  14. }