JS Advance
Advance JS
構造函數constructor Function
1 | function createCard(initName){ |
output
createCard { name: ‘Ma’ }
createCard { name: ‘Ma2’ }
createCard { name: ‘Ma3’ }
array function =>
In ES6 there is a new function called array function, which you can write shorter function.
Before ES6
function hello(){}
after ES6
let hello = function (){}
shorthand
let hello = () =>{}
function without passing paramter
Before ES6 (normal function)
ex: function hello(){}
1 | function test(a ,b){ |
ES6 arrow function:
ex: let hello = () =>{}
1 | const test =(a,b) => {console.log(a, b)} |
function with passing varable and return
Before ES6 (normal function)
ex:
1 | function arrowSum (a , b) { |
ES6 arrow function:
example
function=()=>{return } //with return
function=()=> // Single line arrow function
1 | arrowSum=(a,b)=>{ |
We can either add return or not. Without return we call it implicit return
; values are returned without having to use the return keyword.