Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

0 Replies

Avatar

Level 10

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. :slightly_smiling_face: