I'm working on a project using Easel JS. Opened up the Easel file and the very first line of code confused me:
this.createjs = this.createjs||{};
I know that createjs is invoked when you're setting up your canvas or, for example, creating a bitmap to add to the canvas. But I don't understand the syntax of this line - assign this.createjs or (what I guess is) a blank object to this.createjs?
this.createjs = this.createjs||{};
If this.createjs
is not available/ any falsy
value then you are assigning {}
empty object to this.createjs
.
It's more like,
var a,
b;
b = a || 5;
Since a
is not having any value currently, 5
will be assigned to b
.
Correct. This ensures that if this.createjs
doesn't already exist, an empty object is assigned to it. The ||
is an or operator - if this.createjs
on the left-hand-side evaluates to falsy, it will assign the right-hand-side instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With