identical.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import _objectIs from "./internal/_objectIs.js";
  2. /**
  3. * Returns true if its arguments are identical, false otherwise. Values are
  4. * identical if they reference the same memory. `NaN` is identical to `NaN`;
  5. * `0` and `-0` are not identical.
  6. *
  7. * Note this is merely a curried version of ES6 `Object.is`.
  8. *
  9. * `identical` does not support the `__` placeholder.
  10. *
  11. * @func
  12. * @memberOf R
  13. * @since v0.15.0
  14. * @category Relation
  15. * @sig a -> a -> Boolean
  16. * @param {*} a
  17. * @param {*} b
  18. * @return {Boolean}
  19. * @example
  20. *
  21. * const o = {};
  22. * R.identical(o, o); //=> true
  23. * R.identical(1, 1); //=> true
  24. * R.identical(1, '1'); //=> false
  25. * R.identical([], []); //=> false
  26. * R.identical(0, -0); //=> false
  27. * R.identical(NaN, NaN); //=> true
  28. */
  29. var identical = function (a, b) {
  30. switch (arguments.length) {
  31. case 0:
  32. return identical;
  33. case 1:
  34. return function () {
  35. return function unaryIdentical(_b) {
  36. switch (arguments.length) {
  37. case 0:
  38. return unaryIdentical;
  39. default:
  40. return _objectIs(a, _b);
  41. }
  42. };
  43. }();
  44. default:
  45. return _objectIs(a, b);
  46. }
  47. }; // In order to support Cross-origin Window objects as arguments to identical,
  48. // it cannot be implemented as _curry2(_objectIs).
  49. // The reason is that _curry2 checks if a function argument is the placeholder __
  50. // by accessing a paritcular property. However, across URL origins access
  51. // to most properties of Window is forbidden.
  52. export default identical;