Basic rule is to move logic to from constructor or initialize to execute().
In ES6 class's constructor, super must be called first to refer this.
So we no longer do following logic.
Old way in CoffeeScript
set this.prop
then call super
In parent's constructor behave differently based on this.prop
New way in ES6
always call super first in constructor
set this.prop
in execute, behave differently based on this.prop
Working memo
before conversion
had 2 layer
klass.prototype.ivar
instance.ivar
after conversion
only 1 layer (no prototype.ivar layer)
instance.ivar
Caution
ES6 class is not extendable by CS's class.
Thus, converting breaks user's custom class in their init.coffee(if exists) or vmp-plugin package written in coffee.
CS's executable class body is no longer availale.
Class prop is not set on prototype, and it's set after constructor's super call.
So don't expect these class props are available in parent's constructor.
Basically keep constructor function small and simple.
In CS, Object.assign(this, prop) in constructor can overwrite properties defined in prototype, but in JS, properties are set after construction, so this approach must be replaced with new one.
I experimentally introduce Base.assign as replacement for constructor's 2nd arg(was prop directly Object.assign-ed in constructor.
To let me understand how it is, clarify requirement.
TODO( 🚢 released)
constructor
and if necessary, modify props after construction.Find the way to notify user to inform extending JS class by coffee is no longer supported.I don't thins there is it.Migration best practices memo
constructor
orinitialize
toexecute()
.constructor
,super
must be called first to referthis
.this.prop
super
constructor
behave differently based onthis.prop
super
first inconstructor
this.prop
execute
, behave differently based onthis.prop
Working memo
before conversion
had 2 layer
after conversion
only 1 layer (no
prototype.ivar
layer)Caution
init.coffee
(if exists) or vmp-plugin package written in coffee.prototype
, and it's set after constructor'ssuper
call.constructor
function small and simple.Object.assign(this, prop)
in constructor can overwrite properties defined in prototype, but in JS, properties are set after construction, so this approach must be replaced with new one.Base.assign
as replacement forconstructor
's 2nd arg(was prop directlyObject.assign
-ed in constructor.