0
0

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 1 year has passed since last update.

Angularの省略表記についてのメモ

Last updated at Posted at 2021-02-04

##きっかけ
初めてconstructorの引数を見たときに、処理の内容がわからず混乱した。

##理解した方法

  • 省略されているコードを分解して理解した。備忘録として残す。

class Dog { 
  //コンストラクター
  constructor(private categry: string, private weight: number){}
  
  // toStringメソッド
  public toString {
    return this.category + ':' + this.weight + 'kg'
  }
} 

let name = new Dog('豆柴', 8);
console.log(name.toString()); //結果:豆柴:8kg

//以下のコードと同じ

class Dog{
  //privateプロパティ
  private category: string;
  private weight: number;
  
  public constructor(category: string, weight: number) {
    this.category = category;
    this.weight = weight;
  }

  // toStringメソッド
  public toString {
    return this.category + ':' + this.weight + 'kg'
  }
} 

let name = new Dog('豆柴', 8);
console.log(name.toString()); //結果:豆柴:8kg
0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?