青岛网站设计,亚马逊雨林的原始部落,企业网站建设市场分析,官方网站的资料做证据ES6的系列文章目录 
第一章 Python 机器学习入门之pandas的使用 文章目录 ES6的系列文章目录0、数值的扩展一、函数的扩展1、函数的默认值2、函数的reset参数 二、数组的扩展1. 将对象转成数组的Array.from()2. 将对象转成数组的Array.from()3. 实例方法 find()#xff0c;fin…ES6的系列文章目录 
第一章 Python 机器学习入门之pandas的使用 文章目录 ES6的系列文章目录0、数值的扩展一、函数的扩展1、函数的默认值2、函数的reset参数 二、数组的扩展1. 将对象转成数组的Array.from()2. 将对象转成数组的Array.from()3. 实例方法 find()findIndex()findLast()findLastIndex() 三、对象的扩展1.判断两个对象是否相等 Object.is()2.对象的合并方法 Object.assign()  0、数值的扩展 其实数值的方法有很多但大部分都是稍加了解即可这里着重讲下Number.EPSILON它是 JavaScript 能够表示的最小精度。误差如果小于这个值就可以认为已经没有意义了即不存在误差了。 经典面试题0.1  0.2  0.3 吗 为什么 答案: 不等于。 原因对于 64 位浮点数来说大于 1 的最小浮点数相当于二进制的1.00..001小数点后面有连续 51 个零。 这个值减去 1 之后就等于 2 的 -52 次方。 // 经典面试题0.1  0.2  0.3 吗 为什么  // 1:答案: 不等于。
console.log(0.1  0.2  0.3) // false
console.log(0.1  0.2) // 0.30000000000000004
// 2:原因对于 64 位浮点数来说大于 1 的最小浮点数相当于二进制的1.00..001小数点后面有连续 51 个零。 这个值减去 1 之后就等于 2 的 -52 次方。
console.log(0.1  0.2 - 0.3) // 5.551115123125783e-17
console.log(5.551115123125783e-17.toFixed(20)) // 0.00000000000000005551// 3:如何解决
function equal(a, b) {if(Math.abs(a-b)  Number.EPSILON) {return true;} else {return false;}
}
console.log(0.1  0.2  0.3) // false
console.log(equal(0.1  0.2, 0.3)) // true一、函数的扩展 
1、函数的默认值 简单概况 允许给函数的参数设置默认值。相当于是为函数的参数加了一层保险如果你没有给对应形参数量的实参的保险同时为了更好辨别一般将要设置默认值的放在最后面。 function add (a, b, c10) {return a  b  c;
}
let a1  add(1,2,3);
let a2  add(1,2);
console.log(a1); // 6  123
console.log(a2); // 13 12102、函数的reset参数 es6引入rest参数用于获取函数的实参用来替代arguments 以下为es5和es6的对比及其效果 
// es5
function getUser(){console.log(...arguments);
}
getUser(张三,李四,王五);// es6 的 rest参数
function getAge (a, b, ...c) {console.log(a);console.log(b);console.log(c);  // rest 参数可以是任意名字符合命名规范
}
getAge(1,2,3,4,5,6);二、数组的扩展 
1. 将对象转成数组的Array.from() 
// 1将对象转成数组  Array.from()
letarrayLike  {0: a,1: b,2: c,length: 3
};// 1.1ES5 的写法
var arr1  [].slice.call(arrayLike);
console.log(arr1); // [a, b, c]
// 1.2ES6 的写法
let arr2  Array.from(arrayLike);
console.log(arr2); // [a, b, c]// 1.3arguments 对象
function foo() {var args  Array.from(arguments);console.log(args)
}
foo(1,2,3,4,5,6,7); // [,2,3,4,5,6,7]2. 将对象转成数组的Array.from() 
// 2将一组值转换为数组  Array.of()
// 2.1: 错误示范(参数为1个和两个都错误)
console.log(Array()) // []
console.log(Array(3)); // [空属性 × 3]
// 2.2: 正确示范     
console.log(Array.of(1, 2, 3)) // [1,2,3]
console.log(Array.of(3)) // [3]
console.log(Array.of(3).length) // 13. 实例方法 find()findIndex()findLast()findLastIndex() 
// 3实例方法 find()findIndex()findLast()findLastIndex() 
// 3.1find和findIndex共同点找出第一个符合条件的数组成员。参数是一个回调函数所有数组成员依次执行该回调函数。
// (1)find() 找出第一个返回值为true的成员然后返回该成员。如果没有符合条件的成员则返回undefined。
let a1  [1, 5, 10, 15].find(function(value, index, arr) {return value  9;
}) // 10
console.log(3.1:, a1);
let a2  [1, 5].find(function(value, index, arr) {return value  9;
}) // undefined
console.log(3.1:, a2);
// (2) findIndex() 找出返回第一个符合条件的数组成员的位置如果所有成员都不符合条件则返回-1
let a3  [1, 5, 10, 15].findIndex(function(value, index, arr) {return value  9;
}) // 2
console.log(3.2:, a3);
let a4  [1, 5].findIndex(function(value, index, arr) {return value  9;
}) // -1
console.log(3.2:, a4);
// 3.2findLast和findLastIndex共同点找出最后一个符合条件的数组成员。参数是一个回调函数所有数组成员依次执行该回调函数。
// findLast() “从结尾开始”找出第一个返回值为true的成员然后返回该成员。如果没有符合条件的成员则返回undefined。
// findLastIndex() “从结尾开始”找出返回第一个符合条件的数组成员的位置如果所有成员都不符合条件则返回-1// 3.3注意点indexOf()方法无法识别数组的NaN成员但是findIndex()方法可以借助Object.is()方法做到。
console.log([NaN].indexOf(NaN))// -1
console.log([NaN].findIndex(y  Object.is(NaN, y)))// 0三、对象的扩展 
1.判断两个对象是否相等 Object.is() 
// 1: Object.is  判断两个数值是否完全相等
console.log(Object.is(张三, 张三)) // trueconsole.log(Object.is(18, 18)) // trueconsole.log(Object.is(NaN, NaN)) // true// 注意点严格运算符和 Object.is()的区别:0不等于-0NaN等于自身。console.log(0  -0) // trueconsole.log(NaN  NaN) // falseconsole.log(Object.is(0, -0)) // falseconsole.log(Object.is(NaN, NaN)) // true2.对象的合并方法 Object.assign() 
// 2: Object.assign() 对象的合并方法
//2.1: 合并过程中后面覆盖前面的
let obj  {name: 张三,age: 18,sex: 男
}
let obj1  {name: 李四,age: 19,
}
console.log(Object.assign(obj, obj1));// 2.2 对象的浅拷贝 (复制的对象拷贝得到的是这个对象的引用)
let obj2  Object.assign({}, obj1);
console.log(obj2, obj  obj2); //{name:李四,age:19} false 文章转载自: http://www.morning.bwttp.cn.gov.cn.bwttp.cn http://www.morning.dwdjj.cn.gov.cn.dwdjj.cn http://www.morning.rnpt.cn.gov.cn.rnpt.cn http://www.morning.xyjlh.cn.gov.cn.xyjlh.cn http://www.morning.jfwbr.cn.gov.cn.jfwbr.cn http://www.morning.gcthj.cn.gov.cn.gcthj.cn http://www.morning.mkccd.cn.gov.cn.mkccd.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.hjlsll.com.gov.cn.hjlsll.com http://www.morning.fpqq.cn.gov.cn.fpqq.cn http://www.morning.dnzyx.cn.gov.cn.dnzyx.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.zxgzp.cn.gov.cn.zxgzp.cn http://www.morning.tpqrc.cn.gov.cn.tpqrc.cn http://www.morning.lrnfn.cn.gov.cn.lrnfn.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.yzxlkj.com.gov.cn.yzxlkj.com http://www.morning.qpljg.cn.gov.cn.qpljg.cn http://www.morning.whclz.cn.gov.cn.whclz.cn http://www.morning.wcrcy.cn.gov.cn.wcrcy.cn http://www.morning.rqrxh.cn.gov.cn.rqrxh.cn http://www.morning.wxgd.cn.gov.cn.wxgd.cn http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn http://www.morning.mwnch.cn.gov.cn.mwnch.cn http://www.morning.xnhnl.cn.gov.cn.xnhnl.cn http://www.morning.npmpn.cn.gov.cn.npmpn.cn http://www.morning.prznc.cn.gov.cn.prznc.cn http://www.morning.lfqnk.cn.gov.cn.lfqnk.cn http://www.morning.zmqb.cn.gov.cn.zmqb.cn http://www.morning.crxdn.cn.gov.cn.crxdn.cn http://www.morning.ysybx.cn.gov.cn.ysybx.cn http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.jwwfk.cn.gov.cn.jwwfk.cn http://www.morning.jtfcd.cn.gov.cn.jtfcd.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.kzpy.cn.gov.cn.kzpy.cn http://www.morning.kcsx.cn.gov.cn.kcsx.cn http://www.morning.ljqd.cn.gov.cn.ljqd.cn http://www.morning.yllym.cn.gov.cn.yllym.cn http://www.morning.dmthy.cn.gov.cn.dmthy.cn http://www.morning.kczkq.cn.gov.cn.kczkq.cn http://www.morning.hbywj.cn.gov.cn.hbywj.cn http://www.morning.lskrg.cn.gov.cn.lskrg.cn http://www.morning.lrskd.cn.gov.cn.lrskd.cn http://www.morning.nxdqz.cn.gov.cn.nxdqz.cn http://www.morning.ggxbyhk.cn.gov.cn.ggxbyhk.cn http://www.morning.bmtyn.cn.gov.cn.bmtyn.cn http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn http://www.morning.pmnn.cn.gov.cn.pmnn.cn http://www.morning.fbpdp.cn.gov.cn.fbpdp.cn http://www.morning.ldwxj.cn.gov.cn.ldwxj.cn http://www.morning.shangwenchao4.cn.gov.cn.shangwenchao4.cn http://www.morning.frsxt.cn.gov.cn.frsxt.cn http://www.morning.gqfjb.cn.gov.cn.gqfjb.cn http://www.morning.dbylp.cn.gov.cn.dbylp.cn http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn http://www.morning.dmwck.cn.gov.cn.dmwck.cn http://www.morning.fwnyz.cn.gov.cn.fwnyz.cn http://www.morning.rnds.cn.gov.cn.rnds.cn http://www.morning.bmjfp.cn.gov.cn.bmjfp.cn http://www.morning.kwjyt.cn.gov.cn.kwjyt.cn http://www.morning.mnlk.cn.gov.cn.mnlk.cn http://www.morning.hrgxk.cn.gov.cn.hrgxk.cn http://www.morning.kpcdc.cn.gov.cn.kpcdc.cn http://www.morning.chfxz.cn.gov.cn.chfxz.cn http://www.morning.cwwts.cn.gov.cn.cwwts.cn http://www.morning.rnnts.cn.gov.cn.rnnts.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.kfyjh.cn.gov.cn.kfyjh.cn http://www.morning.pqnkg.cn.gov.cn.pqnkg.cn http://www.morning.mlpch.cn.gov.cn.mlpch.cn http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.pigcamp.com.gov.cn.pigcamp.com http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.pyncx.cn.gov.cn.pyncx.cn http://www.morning.zzgtdz.cn.gov.cn.zzgtdz.cn http://www.morning.nyqxy.cn.gov.cn.nyqxy.cn