# Javascript Invoke FunctionObject from native?

**URL:** <https://forum.juce.com/t/javascript-invoke-functionobject-from-native/12185>\
**Category:** General JUCE discussion\
**Created:** [January 11, 2014, 7:08am UTC](https://forum.juce.com/t/javascript-invoke-functionobject-from-native/12185 "2014-01-11T07:08:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![graeme-2](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@graeme-2](https://forum.juce.com/u/graeme-2)\
**Post date:** [January 11, 2014, 7:08am UTC](https://forum.juce.com/t/javascript-invoke-functionobject-from-native/12185/1 "2014-01-11T07:08:33Z")

</div>

Hey Jules,

I have a Lua gui system that I'm attempting to port over to your Javascript engine. &nbsp;I'm wondering how I can pass a javascript function to native code for execution at a later point. &nbsp;For example, registering functions to fire for&nbsp;"click" events. &nbsp;

&nbsp;

Javascript:

```
//onClick is a method on my registered dynamic object
dyn.onClick(function() {
    //do stuff
});
```

C++

```
static var onClick(Args a) {

    var func = a.arguments[0];
    
    //Debugger shows that it is a JavascriptEngine::RootObject::FunctionObject *
    //but RootObject is private so it's off limits.

}
```

I've just been piecing things together as I go, so I could easily be missing something obvious.

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 11, 2014, 11:10am UTC](https://forum.juce.com/t/javascript-invoke-functionobject-from-native/12185/2 "2014-01-11T11:10:07Z")

</div>

Hmm.. Yes, to do that I think it would need some extra kind of method in the JavascriptEngine class to invoke it.
