1. 程式人生 > 其它 >Vuejs學習筆記(三)-11.箭頭函式

Vuejs學習筆記(三)-11.箭頭函式

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4   <meta charset="UTF-8">
 5   <title>01-箭頭函式</title>
 6 </head>
 7 <body>
 8 <script>
 9   // 1.定義函式的方式1
10 
11 
12   const a = function(){
13 
14   }
15   // 2.定義函式的方式2,物件字面量中定義
16 
17   const obj = {
18 b:function(){ 19 20 }, 21 c(){ 22 23 } 24 } 25 26 // 3.1 es6的箭頭函式 27 // const c = (引數列表)=>{ 28 // 29 // } 30 const c=()=>{ 31 32 } 33 34 // 3.2 有多個引數的箭頭函式 35 36 const sum = (num1,num2) =>{ 37 return num1+num2 38 } 39 40 // 3.3 只有一個引數是小括號可以省略 41 const d = h=>{
42 return h*h 43 } 44 45 // 3.4 函式內部有多行程式碼,正常寫 46 47 const e = ()=>{ 48 console.log('hello world'); 49 console.log('hello vue'); 50 } 51 52 // 3.5 函式返回值只有一行程式碼時,可以省略 53 54 const f = h=> h*h 55 56 // 3.6箭頭函式this的使用 57 // 箭頭函式使用用途最多的場景:當將一個函式作為引數傳入另一個函式內是用箭頭函式比較多。 58 // 如: render: h=>h(app)

以上是箭頭函式的寫法

本文來自部落格園,作者:kaer_invoker,轉載請註明原文連結:https://www.cnblogs.com/invoker2021/p/14982199.html