ES6新特性——对象方法扩展
1.Object.is 判断两个值是否完全相等
<script> console.log(Object.is(120,120)); // true; console.log(Object.is(NaN,NaN)); // true; console.log(NaN === NaN); // false; </script>
2.Object.assign 对象的合并
<script> const config1 = { host: 'localhost', port: 3306, name: 'root', pass: 'root', text: 'text' } const config2 = { host: 'http://xxx.com', port: 33060, name: 'xxx.com', pass: 'zzz', xxx: '123' } console.log(Object.assign(config1,config2)); // config1 config2 中得重复项会被 config2 覆盖掉 ,不重复得会被保留, config2 中得不重复项也会被保留 </script>
3.Object.setPrototypeOf 设置原型对象 Object.getPrototypeOf 获取原型对象
<script> const school = { name: 'xxx', } const cities = { xiaoqu: ['北京','上海','深圳'] } Object.setPrototypeOf(school,cities);
console.log(Object.getPrototypeOf(school)); // 打印出cities对象 console.log(school); // 在school原型对象中添加 cities 对象 </script>

浙公网安备 33010602011771号