LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Thursday, July 19, 2018

アロー関数 () => は function()


すぐ忘れてしまうので備忘録として書き残しておこう


bt.onclick = () => { alert("hello") };



bt.onclick = function() { alert("hello") };




コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
  <body>
    <button id="bt">bt</button>
    <script>
      bt.onclick = function() { alert("hello") };
      //bt.onclick = () => { alert("hello") };
    </script>
  </body>
</html>
意訳
 


ボタン

ボタンをクリックしたらアラートを出す
アロー関数で書くとこう





参考

アロー関数
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/arrow_functions
引数が1つのときは()を省略できる

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...