「React ES6」クラスのメソッドを使うサンプル

書式
class クラス名{
メソッド名(){xxx}
}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
class Person {
 //コンストラクタ
constructor(name) {
this.user = name;
}
//メソッド
funcA() {
return 'this is a ' + this.user;
}
}
//オブジェクトを生成
obj = new Person("test message");
document.write(obj.funcA());
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> class Person {  //コンストラクタ constructor(name) { this.user = name; } //メソッド funcA() { return 'this is a ' + this.user; } } //オブジェクトを生成 obj = new Person("test message"); document.write(obj.funcA()); </script> </body> </html>
<!DOCTYPE html>
<html>

<body>
  
<script>
class Person {
  //コンストラクタ
  constructor(name) {
    this.user = name;
  }
  //メソッド
  funcA() {
    return 'this is a ' + this.user;
  }
}
//オブジェクトを生成
obj = new Person("test message");
document.write(obj.funcA());
</script>

</body>
</html>

 

React.js

Posted by arkgame