Object

# Object

# entries

// 将对象转成键值对数组
Object.prototype.lamb_entries = function (obj) {
  const res = [];
  for (let key in obj) {
    obj.hasOwnProperty(key) && res.push([key, obj[key]]);
  }
  return res;
};

# fromEntries

// 将键值对数组转成对象
Object.prototype.lamb_fromEntries = function (arr) {
  const obj = {};
  for (let i = 0; i < arr.length; i++) {
    const [key, value] = arr[i];
    obj[key] = value;
  }
  return obj;
};

# keys

// 将对象的key转成一个数组合集
Object.prototype.lamb_keys = function (obj) {
  const keys = [];
  for (let key of obj) {
    obj.hasOwnProperty(key) && keys.push(key);
  }
  return keys;
};

# values

// 将对象所有的值转成数组集
Object.prototype.lamb_values = function (obj) {
  const values = [];
  for (let key of obj) {
    obj.hasOwnProperty(key) && keys.push(obj[key]);
  }
  return values;
};

# instanceOf

// 遍历原型链即可
function lamb_instanceOf(A, B) {
  let p = A;
  while (p) {
    if (p === B.prototype) {
      return true;
    }
    p = p.__proto__;
  }
  return false;
}

# is

// Object.is(a, b),判断a是否等于b
Object.prototype.lamb_is = function (a, b) {
  if (x === y) {
    // 防止 -0 和 +0
    return x !== 0 || 1 / x === 1 / y;
  }

  // 防止NaN
  return x !== x && y !== y;
};