对象方法扩展 Object.is Object.assign Object.setPrototypeOf 设置原型对象 Object.getPrototypeOf 获取原型对象

   // 1 Object.is 判断两个值是否完全相等
    // console.log(Object.is(120,121)); // false
    // console.log(Object.is(120,120)); // true
    // console.log(Object.is(NaN,NaN)); // true

    // 2 Object.assign 对象的合并
    // const config1 = {
    //   host:'localhost',
    //   port:3306,
    //   name:'root',
    //   pass:'root',
    //   test:'test'
    // }

    // const config2 = {
    //   host:'http://127.0.0.1',
    //   port:33060,
    //   name:'Eric',
    //   pass:'IloveU',
    //   test2:'test2'
    // }

    // // 后面会把前面的给覆盖
    // let res = Object.assign(config1,config2); 
    // console.log(res);

    // 3 Object.setPrototypeOf 设置原型对象 Object.getPrototypeOf 获取原型对象
    const city = {
      name:'北京'
    };

    const area = {
      xiaoqu: ['朝阳','海淀','昌平']
    };

    // 设置原型对象
    Object.setPrototypeOf(city,area);
    console.log(city);

    // 获取原型对象
    console.log(Object.getPrototypeOf(city));
posted @ 2021-05-18 23:21  13522679763-任国强  阅读(62)  评论(0)    收藏  举报