es6.function.name.js 652 B

12345678910111213141516171819202122232425
  1. var dP = require('./_object-dp').f
  2. , createDesc = require('./_property-desc')
  3. , has = require('./_has')
  4. , FProto = Function.prototype
  5. , nameRE = /^\s*function ([^ (]*)/
  6. , NAME = 'name';
  7. var isExtensible = Object.isExtensible || function(){
  8. return true;
  9. };
  10. // 19.2.4.2 name
  11. NAME in FProto || require('./_descriptors') && dP(FProto, NAME, {
  12. configurable: true,
  13. get: function(){
  14. try {
  15. var that = this
  16. , name = ('' + that).match(nameRE)[1];
  17. has(that, NAME) || !isExtensible(that) || dP(that, NAME, createDesc(5, name));
  18. return name;
  19. } catch(e){
  20. return '';
  21. }
  22. }
  23. });