本文主要介绍 24 中 es6 方法,这些方法都挺实用的,本本请记好,时不时翻出来看看. 1.如何隐藏所有指定的元素 const hide = (el) => Array.from(el).forEach(e => (e.style.display = 'none')); // 事例:隐藏页面上所有`<img>`元素? hide(document.querySelectorAll('img')) 2.如何检查元素是否具有指定的类? 页面DOM里的每个节点上都有一个classList…
2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼,以牙还牙,以手还手,以脚还脚,…
2016年12月3日 星期六 --出埃及记 Exodus 20:24 "`Make an altar of earth for me and sacrifice on it your burnt offerings and fellowship offerings, your sheep and goats and your cattle. Wherever I cause my name to be honored, I will come to you and bless you. 你要为我…
2016年11月8日 星期二 --出埃及记 Exodus 19:24 The LORD replied, "Go down and bring Aaron up with you. But the priests and the people must not force their way through to come up to the LORD, or he will break out against them." 耶和华对他说,下去吧,你要和亚伦一同上来,只是祭司和百姓不可…
2016年10月13日 星期四 --出埃及记 Exodus 18:24 Moses listened to his father-in-law and did everything he said.于是,摩西听从他岳父的话,按着他所说的去行.…
2016年6月27日 星期一 --出埃及记 Exodus 14:24 During the last watch of the night the LORD looked down from the pillar of fire and cloud at the Egyptian army and threw it into confusion. 到了晨更的时候,耶和华从云火柱中向埃及的军兵观看,使埃及的军兵混乱了,…
假如有这样一个数组.arr = [12,34,45,46,36,58,36,59],现在要遍历该数组. 方法1:以前我们可能会这样做: for(var i=0;i<arr.length;i++){ console.log(arr[i]+"\n") } 方法2:自ES5发布后,我们可以使用内置的forEach方法来遍历数组. arr.forEach(function(val){ console.log(val+"\n") }) 这段代码看起来简单,然而有些缺陷,…
So,也许你觉得ES6让你视野大开,但是并不是性能也能跟得上~ 首先,让我们先来一个简单的性能测试: 数组去重 es5写法: function delSame(arr){ var n = []; ; i < arr.length; i++){ ) n.push(arr[i]); } return n; } es6极简写法: function es6DelSame(arr){ return Array.from(new Set(arr)) } 测试性能的方法当然是用console.time();函…
现在很多功能用es5的方法也能实现功能,但es6提供的方法显得更为高效.记录下目前常用的几个方法. 1.字符包含 通过str.includes('a')来判断, 若str中包含a则结果为true,否则为false. eg: let str = 'abcd'; console.log(str.includes('a')); // true console.log(str.includes('f')); // false 此外,支持第二个参数: console.log(str.includes('d…
常用的ES6方法 ES6之后,新增了定义变量的两个关键字,分别是let和const. let和const都能够声明块级作用域,用法和var是类似的,let的特点是不会变量提升,而是被锁在当前块中. 实例-1: 唯一正确的使用方法:先声明-->再访问 const 声明常量,一旦声明,不可更改,而且常量必须初始化赋值. const虽然是常量,不允许修改默认赋值,但如果定义的是对象Object,那么可以修改对象内部的属性: const和let的异同点 相同点: const和let都是在当前块内有效,执…