isEqualWith.js 800 B

12345678910111213141516171819202122232425
  1. var helperEqualCompare = require('./helperEqualCompare')
  2. var helperDefaultCompare = require('./helperDefaultCompare')
  3. var isFunction = require('./isFunction')
  4. var isUndefined = require('./isUndefined')
  5. /**
  6. * 深度比较两个对象之间的值是否相等,使用自定义比较函数
  7. *
  8. * @param {Object} obj1 值1
  9. * @param {Object} obj2 值2
  10. * @param {Function} func 自定义函数
  11. * @return {Boolean}
  12. */
  13. function isEqualWith (obj1, obj2, func) {
  14. if (isFunction(func)) {
  15. return helperEqualCompare(obj1, obj2, function (v1, v2, key, obj1, obj2) {
  16. var result = func(v1, v2, key, obj1, obj2)
  17. return isUndefined(result) ? helperDefaultCompare(v1, v2) : !!result
  18. }, func)
  19. }
  20. return helperEqualCompare(obj1, obj2, helperDefaultCompare)
  21. }
  22. module.exports = isEqualWith