es6 -箭頭函式:
//es6 中的箭頭函式和擴充套件
//es5的寫法
//function add(a,b)
//add(1,2); //3
function add1(a,b=1)
return a+b;
} //uncaught error: a is zero 主動丟擲異常
//嚴謹模式
function
add(a,b)
console.log(add(1)) //
nan console.log(add(1,2)) //3//
獲取引數個數
console.log(add.length) //
2function add2(a,b=1)
console.log(add2.length)
//1 獲取的引數是必須傳遞引數的個數 當給a複製後 輸出 0
//箭頭函式
//箭頭函式中不允許使用new的 箭頭函式中不能寫建構函式
//方法體只有一行的時候 不用加上花括號
var add3 = (a,b=1) => a+b;
console.log(add3(2)) //3//
方法體有多行的時候 需要加上花括號
var add4 = (a,b) =>
console.log(add4(1,2)) //
3
物件的函式解構
//物件的函式解構
let json =
console.log(json.a)
//輸出 ananiah
function fun()
fun(json);
es6箭頭函式
本例是在了解es6知識後在原來定義函式的基礎上進行理解var searchvalue 查詢匹配物件 var button var input var select button if searchvalue.input undefined button.click else 重新整理 tableli...
es6 箭頭函式
1.單引數 function cheng a 3 let cheng a 3 a a console.log cheng 9 2.多引數 function add a,b let add a,b a b 預設返回值 console.log add 3,9 3.無返回值 function add a,...
ES6 箭頭函式
es6 中,箭頭函式就是函式的一種簡寫形式,使用括號包裹數,跟隨乙個 緊接著是函式體 var getprice function 箭頭函式 var getprice 9.15 箭頭函式不僅僅是讓 變得簡潔,函式中 this 總是繫結總shi 指向物件自身 function person 1000 使...