Created
April 3, 2022 09:22
-
-
Save tio-iis/5b3604583b8d235187e0fe2f2934225c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
//staticなプロパティ | |
//Userクラスによって生成されたオブジェクトから利用することはできない。 | |
static staticProperty = "this is staticProperty" | |
constructor(name) { | |
//通常のプロパティ | |
this.name = name | |
} | |
//通常のメソッド | |
normalGetName() { | |
return this.name + "-san" | |
} | |
//staticなメソッド | |
//Userクラスによって生成されたオブジェクトから利用することはできない。 | |
static staticGetName() { | |
//thisによってクラスが持つプロパティを参照することはできない。 | |
//return this.name + "-san" | |
//staticなメソッドを参照することはできる。 | |
console.log(User.myStaticMethod()) | |
//staticなプロパティを参照することはできる。 | |
return User.staticProperty | |
} | |
static myStaticMethod() { | |
return "my static method" | |
} | |
//通常のメソッド内でstaticなプロパティとメソッドを利用することができる。 | |
useStaticInNormalMethod() { | |
return User.staticGetName() + " / " + User.staticProperty | |
} | |
} | |
//var d = Date.now() | |
console.log(Math.round(0.5)) | |
//var iistio = new User("iistio") | |
//console.log(iistio.name) | |
//console.log(iistio.normalGetName()) | |
//var suzuki = new User("suzuki") | |
//console.log(suzuki.name) | |
//console.log(suzuki.normalGetName()) | |
//console.log(User.staticGetName()) | |
//console.log(User.staticProperty) | |
//console.log(iistio.useStaticInNormalMethod()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment