一群棒子
  • 首頁
  • 作者
  • 關於我們
Tagged

ES6

A collection of 2 posts

ES6 學習筆記(二) 箭頭函數的 this
JavaScript

ES6 學習筆記(二) 箭頭函數的 this

那麼在先前已經學習過了箭頭函數的寫法,有沒有又覺得自己又潮了一點,箭頭函數並不只是單純寫法上的改變,另一個好處是箭頭函數的 this 是綁定父級作用域的,這麼說不太清楚不如直接看程式碼比較快。 範例 先來一段常常會見到的錯誤範例 const person = { name: 'jimmy', skills: ['html', 'css', 'php', 'js', 'vue', 'drupal', 'wordpress', 'laravel'], getSkills: function () { this.skills.map(function (skill) { // console.log(this)

  • jimmy8646
jimmy8646 2018年7月2日 • 2 min read
ES6 學習筆記(一) 箭頭函數
JavaScript

ES6 學習筆記(一) 箭頭函數

寫碼容易讀碼難,在 JavaScript ES6 中有一個語法叫做 箭頭函數(arrow function)他的語法讓程式碼更加的簡短,以下是一段簡單的程式碼範例。 範例 const arr = [1,3,5,7,9] const double = arr.map(function(arr){ return arr*2 }) console.log(double) // [2, 6, 10, 14, 18] //箭頭函數 const arr = [1,3,5,7,9] const double = arr.map((arr) => { return

  • jimmy8646
jimmy8646 2018年6月24日 • 2 min read
一群棒子 © 2025
Powered by Ghost