map和set
1. map
2.set
3.iterable类型(Array、Map、Set)
Array(map和reduce方法)
1.map
由于map()方法定义在JavaScript的Array中,我们调用Array的map()方法,传入我们自己的函数,就得到了一个新的Array作为结果:
2.reduce
再看reduce的用法。Array的reduce()把一个函数作用在这个Array的[x1, x2, x3…]上,这个函数必须接收两个参数,reduce()把结果继续和序列的下一个元素做累积计算,其效果就是:
3.filter
filter()把传入的函数依次作用于每个元素,然后根据返回值是true还是false决定保留还是丢弃该元素。
例如,在一个Array中,删掉偶数,只保留奇数,可以这么写:
4.sort
通常规定,对于两个元素x和y,如果认为x < y,则返回-1,如果认为x == y,则返回0,如果认为x > y,则返回1,这样,排序算法就不用关心具体的比较过程,而是根据比较结果直接排序。
Array的sort()方法默认把所有元素先转换为String再根据ASCII码进行排序
箭头函数
相当于
箭头函数和匿名函数有个明显的区别:箭头函数内部的this是词法作用域,由上下文确定。
由于this在箭头函数中已经按照词法作用域绑定了,所以,用call()或者apply()调用箭头函数时,无法对this进行绑定,即传入的第一个参数被忽略:
Date
JavaScript的月份范围用整数表示是0~11,0表示一月,1表示二月……
JSON
generator
- 形式上,Generator函数是一个普通函数,但是有两个特征。一是,function关键字与函数名之间有一个星号;二是,函数体内部使用yield语句,定义不同的内部状态.
- 调用Generator函数,返回一个遍历器对象,代表Generator函数的内部指针。以后,每次调用遍历器对象的next方法,就会返回一个有着value和done两个属性的对象。value属性表示当前的内部状态的值,是yield语句后面那个表达式的值;done属性是一个布尔值,表示是否遍历结束。
class和原型继承
浏览器
- window对象不但充当全局作用域,而且表示浏览器窗口。window.innerWidth window.innerHeight可以获取浏览器窗口的内部宽度和高度。内部宽高是指除去菜单栏、工具栏、边框等占位元素后,用于显示网页的净宽高。对应的,还有一个outerWidth和outerHeight属性,可以获取浏览器窗口的整个宽高。
- navgator.userAgent
- screen表示屏幕的信息属性有:
- screen.width:屏幕宽度,以像素为单位;
- screen.height:屏幕高度,以像素为单位;
- screen.colorDepth:返回颜色位数,如8、16、24。
- location对象表示当前页面的URL信息
- document对象表示当前页面。由于HTML在浏览器中以DOM形式表示为树形结构,document对象就是整个DOM树的根节点。document对象还有一个cookie属性,可以获取当前页面的Cookie。
- history对象保存了浏览器的历史记录,这个对象属于历史遗留对象,任何情况,你都不应该使用history这个对象了。
HTML5 fileReader API