要旨
class Person { constructor(name, height, weight) { this.name = name this.height = height this.weight = weight } getData () { return { name: this.name, height: this.height, weight: this.weight, } } } taro = new Person('taro', 180, 60) console.log(taro.getData()) // => {name: 'taro', height: 180, weight: 60}
詳細
Rubyで書いたらこんな感じ。
class Person def initialize(name, height, weight) @name = name @height = height @weight = weight end def getData return { name: @name, height: @height, weight: @height, } end end taro = Person.new('taro', 180, 60) taro.getData # => {:name=>"taro", :height=>180, :weight=>180}
classの定義はホイスティングされないので注意。