Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Pass "this" as a function parameter

Avatar

Level 4

Hi there,

I would like to move most of my (javascript) event code to functions in script objects.

Now I simply can't find out how to pass "this" as a parameter to a function.

The naive way is certainly wrong:

sDummy = MyScriptObject.myFunction(this);


function myFunction(myObject) {

     return myObject.rawValue; }

Has anyone found a way to solve this?

It certainly would help to reuse code substantially.

Thanks in advance

Ulrich

2 Replies

Avatar

Former Community Member

Just tried it here and it works for me .....what are you expecting to happen? I added an app.alert(sDummy) and it displayed the value for me.

Paul

Avatar

Level 4

Paul, I was confused. Thanks for kicking me in the ass to try it again!

My problem was not parameter passing. It turned out I misinterpreted the error message.

Folks, go ahead and keep using the script objects! It is worth it. And there is now problem to pass "this" as a parameter to your functions. :-)