Is it possible to turn a constructor into a block?

For a while now I’ve been making an extension and I tried to make the constructor of a class that I defined into a block. What I had in mind was that when you used the block, on the JavaScript side of things it would simply initialize a new object of that class. This is not what happened. It just tried to call a method that didn’t exist on the class called “__constructor.” I was wondering if turning constructors into blocks was supported, and if so, how would I?

1 Like

We don’t directly map to constructors when instantiating new objects in blocks for simplicity - the typical approach is to create a factory function that returns a new instance of the object, e.g. statusbars.create https://github.com/jwunderl/pxt-status-bar/blob/master/status-bar.ts#L748 or sprites.create

1 Like

Thank you for the information! It’s greatly appreciated. :slight_smile: