object.js 751 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var _ = require('../util')
  2. var objectAgumentations = Object.create(Object.prototype)
  3. /**
  4. * Add a new property to an observed object
  5. * and emits corresponding event
  6. *
  7. * @param {String} key
  8. * @param {*} val
  9. * @public
  10. */
  11. _.define(
  12. objectAgumentations,
  13. '$add',
  14. function $add (key, val) {
  15. if (this.hasOwnProperty(key)) return
  16. this.__ob__.convert(key, val)
  17. this.__ob__.binding.notify()
  18. }
  19. )
  20. /**
  21. * Deletes a property from an observed object
  22. * and emits corresponding event
  23. *
  24. * @param {String} key
  25. * @public
  26. */
  27. _.define(
  28. objectAgumentations,
  29. '$delete',
  30. function $delete (key) {
  31. if (!this.hasOwnProperty(key)) return
  32. delete this[key]
  33. this.__ob__.binding.notify()
  34. }
  35. )
  36. module.exports = objectAgumentations