# Method without class instance

**URL:** https://forum.makecode.com/t/method-without-class-instance/4592
**Category:** micro:bit
**Created:** [November 23, 2020, 11:09pm UTC](https://forum.makecode.com/t/method-without-class-instance/4592 "2020-11-23T23:09:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)
#### Post date: [November 23, 2020, 11:09pm UTC](https://forum.makecode.com/t/method-without-class-instance/4592/1 "2020-11-23T23:09:58Z")

</div>

Hi everyone.

I’m wondering if anyone can either let me know how to do what I’m trying to do, or suggest an alternative?

Let’s set up a simple example of 3 blocks:

Block 1. Creates a class instance  
Block 2. Gets a class variable  
Block 3. Sets a class variable

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/242cc5e6fba4f12a5c1a6086d758d0677a6d8cc0.png)

Is there a way for someone to drag Block 2 or 3 out and have it recognize that it’s class has not been initialized, call class initializer itself, and pass its handle to the instance back to the “this” instance that blockly fetches?

In my example above, I used blockly to set my default class instance object name as “classTest”  
`
//% this.defl=“classTest”
`

I’d love to be able to do a check within a method such as:  
`
if(!this)
{
let handle = createInstance()
this = handle
}
`  
And that would assign my default class instance “classTest” so that I would not get a null error.  
I don’t know if that would have to happen at the blockly level or some other way.

Any help would be appreciated.

Thanks,  
Josh
