setToString.d.ts 1.2 KB

1234567891011121314151617
  1. /**
  2. * If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
  3. * cannot have the property changed using a "=" assignment operator. If using strict mode, attempting that will cause an error. If not using
  4. * strict mode, attempting that will be silently ignored.
  5. *
  6. * If the Object prototype is frozen, inherited non-writable properties can still be shadowed using one of two mechanisms:
  7. *
  8. * 1. ES6 class methods: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#methods
  9. * 2. Using the `Object.defineProperty()` static method:
  10. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
  11. *
  12. * However, this project uses Babel to transpile ES6 classes, and transforms ES6 class methods to use the assignment operator instead:
  13. * https://babeljs.io/docs/babel-plugin-transform-class-properties#options
  14. *
  15. * Therefore, the most compatible way to shadow the prototype's "toString" property is to define a new "toString" property on this object.
  16. */
  17. export declare function setToString(object: object, toStringFn: () => string): void;