$.redefine.js 898 B

123456789101112131415161718192021222324252627
  1. // add fake Function#toString
  2. // for correct work wrapped methods / constructors with methods like LoDash isNative
  3. var global = require('./$.global')
  4. , hide = require('./$.hide')
  5. , SRC = require('./$.uid')('src')
  6. , TO_STRING = 'toString'
  7. , $toString = Function[TO_STRING]
  8. , TPL = ('' + $toString).split(TO_STRING);
  9. require('./$.core').inspectSource = function(it){
  10. return $toString.call(it);
  11. };
  12. (module.exports = function(O, key, val, safe){
  13. if(typeof val == 'function'){
  14. val.hasOwnProperty(SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
  15. val.hasOwnProperty('name') || hide(val, 'name', key);
  16. }
  17. if(O === global){
  18. O[key] = val;
  19. } else {
  20. if(!safe)delete O[key];
  21. hide(O, key, val);
  22. }
  23. })(Function.prototype, TO_STRING, function toString(){
  24. return typeof this == 'function' && this[SRC] || $toString.call(this);
  25. });