LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
You can easily set properties in constructor functions and in methods using the object setting parameter shorthand.
and the example in the doc:
class A
(@x) ->
f: (@y) ->
@x + @y
a = new A 2
a.x #=> 2
a.f 3 #=> 5
a.y #=> 3
test case: with shorthand syntax
If we firstly assign some values such as rows and columns, and then use these values later in the constructor, there is a bug.
class Test
(@rows, @columns) ->
@grid = do
row <- Object.keys(Array(@rows).fill(0)) .map
column <- Object.keys(Array(@columns).fill(0)) .map
"#{row},#{column}"
t = new Test(3,3)
console.log t
In the constructor of class, if we set properties using the shorthand, there seems to be a bug.
Background
the shorthand syntax in the doc:
and the example in the doc:
test case: with shorthand syntax
If we firstly assign some values such as
rows
andcolumns
, and then use these values later in the constructor, there is a bug.the result is
The
grid
is not what we expected.test case: without shorthand syntax
the result is
This works well.
I don't know if this condition is intended.
Update:
Sorry it is not a bug. There is a error in my code about the
this
bounds.