We can of course do:
class Person
constructor: (firstName, lastName) ->
this.firstName = firstName;
this.lastName = lastName;
name: ->
"#{this.first_name} #{this.last_name}"
setName: (name) ->
names = name.split " "
this.firstName = names[0]
this.lastName = names[1]
new Person "Alice" "Fort"
But we can’t do:
new class
constructor: (firstName, lastName) ->
this.firstName = firstName;
this.lastName = lastName;
name: ->
"#{this.first_name} #{this.last_name}"
setName: (name) ->
names = name.split " "
this.firstName = names[0]
this.lastName = names[1]
"Alice" "Fort"
Any possible workaround?
No, it’s a spin-off of IIFE (immediatly invoked function expression, with class to stand in for function)