# Is it possible to turn a constructor into a block?

**URL:** https://forum.makecode.com/t/is-it-possible-to-turn-a-constructor-into-a-block/28097
**Category:** Help
**Tags:** extension
**Created:** [April 5, 2024, 4:45pm UTC](https://forum.makecode.com/t/is-it-possible-to-turn-a-constructor-into-a-block/28097 "2024-04-05T16:45:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ARandomGuyOnMakeCode](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/arandomguyonmakecode/32/22983_2.png) [@ARandomGuyOnMakeCode](https://forum.makecode.com/u/ARandomGuyOnMakeCode)
#### Post date: [April 5, 2024, 4:45pm UTC](https://forum.makecode.com/t/is-it-possible-to-turn-a-constructor-into-a-block/28097/1 "2024-04-05T16:45:17Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [April 5, 2024, 4:47pm UTC](https://forum.makecode.com/t/is-it-possible-to-turn-a-constructor-into-a-block/28097/2 "2024-04-05T16:47:54Z")

</div>

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](https://github.com/jwunderl/pxt-status-bar/blob/master/status-bar.ts#L748) or sprites.create

---

<div class="post-metadata">

### Author: ![ARandomGuyOnMakeCode](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/arandomguyonmakecode/32/22983_2.png) [@ARandomGuyOnMakeCode](https://forum.makecode.com/u/ARandomGuyOnMakeCode)
#### Post date: [April 5, 2024, 4:57pm UTC](https://forum.makecode.com/t/is-it-possible-to-turn-a-constructor-into-a-block/28097/3 "2024-04-05T16:57:42Z")

</div>

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