CoffeeScriptを使用してRubyスタイルでオブジェクトを作成したいと思います。だから私は次のようなことをしたい
class A
constructor: (@params) ->
a = new A {send: true, name: "fit"}
a.send #true
これを行うための「標準的な」方法はありますか?
CoffeeScriptを使用してRubyスタイルでオブジェクトを作成したいと思います。だから私は次のようなことをしたい
class A
constructor: (@params) ->
a = new A {send: true, name: "fit"}
a.send #true
これを行うための「標準的な」方法はありますか?
直接行う方法はありません。そのようなことを行うためのコードを持つ基本クラスを定義することができます
class Base
constructor: (props) ->
for key, value of props
@[key] = value
class Extend extends Base
constructor: (props) ->
super props
alert "#{@key1}, #{@key2}"
e = new Extend 'key1': 'val1', 'key2': 'val2'
alert "#{e.key1}, #{e.key2}"