extend.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * @Author: Rindy
  3. * @Date: 2021-09-14 20:02:23
  4. * @LastEditors: Rindy
  5. * @LastEditTime: 2021-09-14 20:03:48
  6. * @Description:
  7. */
  8. /**
  9. * 对象属性拷贝
  10. *
  11. * @param {Object} target 目标对象
  12. * @param {Object} source 源对象
  13. * @return {Object} 返回目标对象
  14. */
  15. export function extend(target, source) {
  16. for (var key in source) {
  17. if (source.hasOwnProperty(key)) {
  18. var value = source[key]
  19. if (typeof value !== 'undefined') {
  20. target[key] = value
  21. }
  22. }
  23. }
  24. return target
  25. }
  26. /**
  27. * 构建类之间的继承关系
  28. *
  29. * @param {Function} subClass 子类函数
  30. * @param {Function} superClass 父类函数
  31. */
  32. export function inherits(subClass, superClass) {
  33. /* jshint -W054 */
  34. var subClassProto = subClass.prototype
  35. var F = new Function()
  36. F.prototype = superClass.prototype
  37. subClass.prototype = new F()
  38. subClass.prototype.constructor = subClass
  39. extend(subClass.prototype, subClassProto)
  40. /* jshint +W054 */
  41. }