set.js 497 B

123456789101112131415161718192021
  1. export default (function set(object, property, value, receiver) {
  2. var desc = Object.getOwnPropertyDescriptor(object, property);
  3. if (desc === undefined) {
  4. var parent = Object.getPrototypeOf(object);
  5. if (parent !== null) {
  6. set(parent, property, value, receiver);
  7. }
  8. } else if ("value" in desc && desc.writable) {
  9. desc.value = value;
  10. } else {
  11. var setter = desc.set;
  12. if (setter !== undefined) {
  13. setter.call(receiver, value);
  14. }
  15. }
  16. return value;
  17. });