# "this" inside setTimeout

**URL:** https://forum.kirupa.com/t/this-inside-settimeout/287273
**Category:** flash
**Created:** [April 29, 2009, 1:07am UTC](https://forum.kirupa.com/t/this-inside-settimeout/287273 "2009-04-29T01:07:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Pier25](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pier25](https://forum.kirupa.com/u/Pier25)
#### Post date: [April 29, 2009, 1:07am UTC](https://forum.kirupa.com/t/this-inside-settimeout/287273/1 "2009-04-29T01:07:27Z")

</div>

Hi everyone! It’s been a long since I posted a new thread… ahh good old kirupa forum 🙂

Anyway… I have a class which I pass a config object when instantiated. in this object I pass a scope param to be able to call functions and vars from the main class. Like this

```auto

trace(this)// gives me [object NameOfTheDocumentClass]

var myObj = new MyClass({scope:this});

```

… so from inside the MyClass I do this to call myFunction on the main document class:

```auto

config.scope.myFunction();

```

Problem is, now I want to instantiate the class inside a setTimeout and that doesn’t work, because “this” refers to something else… and not the document class.

```auto

myTimeout = setTimeout(function(){
  trace(this)// now gives me [object global] instead of the document class
  var myObj = new MyClass({scope:this});
},1000);

```

I found a solution to this problem, but I’d like to know how could a reference the main class in this situation… and why this becomes [object global] ???

Regards and happy coding 😉
