ES6

基本知识

字符串

//静态字符串一律使用单引号或反应好,不使用双引号,动态字符串用反引号
let num = 100 ;
console.log(`abc${num}def`);   //abc100def

解构

var obj = {nme:'tom' , age:19}
//属性要一致
function fn( {nme,age}){
    console.log(nme,age);
}
fn( obj )   //tom 19
var arr = ['abc',12,'文字'] ;
var arrs = [...arr] ;
console.log(arrs);   //['abc',12,'文字']

类数组

function fn( a , b , ...args ){
    console.log(a);
    console.log(b);
    console.log(args[0]);
}

fn( 'a' , 'b' , [1, 2, 3] )   //a  b  [1,2,3]

函数参数默认值

function fn( a=1 , b=2 ){
    console.log( a+b )
}

fn(2)   //4
fn(3,2)  //5
fn()  //3

bind

function fn(){
    this.i = 0 ;

    setInterval(function(){
        console.log( this.i++ )
    }.bind(this) , 500)
}

fn()    //1 2 3 4 5 6....
function fn(){
    this.i = 0 ;

    setInterval( ()=>{
        console.log( this.i++ )
    } , 500)
}

fn()    //1 2 3 4 5 6....

继承

- 寄生式继承

语句与表达式

js中语句优先,可以解释成语句就不会解释成表达式
var a = { x:1 } ;
x是label   
1是statement
逗号是表达式,结果是最后一个
{ a:1 , b:2 }  逗号后必须是表达式,这里不是所以报错

高阶函数

回调函数

//把函数当做参数传入
var arr = [1,2,3,4,5] ;
arr.forEach(function( item ){
    console.log( item ) 
});

闭包

  • 闭包定义
function fn(){
    var i = 0 ;
    return function(){
        return ++i ;
    }
}
var f = fn() ;
f()
  • 闭包
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值