Reputation: 2495
I want to create objects in Ruby style with CoffeeScript. So I want to do something like
class A
constructor: (@params) ->
a = new A {send: true, name: "fit"}
a.send #true
Is there any "standard" way to do this?
Upvotes: 0
Views: 310
Reputation: 120268
There is no way to do it directly. You could define a base class that has code to do it, like such
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}"
Upvotes: 1