0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

40 代おっさん GASのメソッドを学ぶ

Last updated at Posted at 2022-02-17

本記事ついて

本記事は プログラミング初学者の私が学習していく中でわからない単語や概要をなるべくわかりやすい様にまとめたものです。
もし誤りなどありましたらコメントにてお知らせいただけるとありがたいです。

メソッドとは

メソッドとは
関数が格納されたプロパティのこと
オブジェクトの要素として関数を持たせた場合はメソッドと呼ぶ

構文

メソッド: function (仮引数1, 仮引数2, ...) {
  //処理
}

メソッドは以下の書式で呼び出すことが可能

オブジェクト.メソッド(引数1, 引数2, ...)

*メソッドの場合はドット記法で呼び出すのが一般的

お試し

function toshiki() {
  const like = {
    tosikiLike: function() {
      return '利樹大好き';
    }
  };

  console.log(like.tosikiLike());
}

メソッドの追加

メソッドも代入ができる。
オブジェクトに存在しないメソッドを代入すると追加になる。

構文

オブジェクト.メソッド = function (仮引数1, 仮引数2, ...) {
  //処理
}

お試し

function toshiki() {
  const like = {
    tosikiLike: function() {
      return '利樹大好き';
    }
  };

  like.tosikiMikan = function() {
    return 'みかん好きです';
  }

  console.log(like.tosikiLike());
  console.log(like.tosikiMikan());
}

メソッド定義

コード量が多くなり、見づらくなるため
簡略化して記述できるメソッド構文が用意されている。

構文

メソッド (仮引数1, 仮引数2, ...) {
  //処理
}

お試し

function toshiki() {
  const like = {
    tosikiLike() {
      return '利樹大好き';
    }
  };

  console.log(like.tosikiLike());
}

参考資料

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?