Why is there "action===update" inside the function parameters?

phantom7
Giga Expert

Hello~

I have a quick question, I ran across this transform script, and there is this part that I don't understand:

action === "update"

Can someone please explain it to me? mainly why is there a check for update, does that mean that if it is not update, then the code inside the transformRow function will not be executed?

(function transformRow(source, target, map, log, isUpdate) {
......
})(source, target, map, log, action==="update");
1 ACCEPTED SOLUTION

ARG645
Tera Guru

To explain this, we first need to know self-executable functions in Javascript. The parameter passing in a self-executable function is defined in the bottom portion of it. 

(function(param1, param2, param3) {
   if(param3){//True
     gs.log(param1);//Eggs
     gs.log(param2);//Cheese
   }
})("eggs","cheese",true);

 

The script you found, is setting isUpdate to true based on the action parameter. it doesn't mean the script won't execute if it's not an update operation, the answer really depends on how the script is defined inside the function.

By the way, where did you find this code? and can you post the function body?

Thank you,

Aman Gurram

Please mark the answer correct/helpful if applicable! 

View solution in original post

2 REPLIES 2

James Bengel
Giga Expert

If I had to guess, I would guess that the isUpdate argument is a boolean and being assigned the value of the expression action==="update".  It's a clever, if somewhat opaque way of passing in a flag telling the function whether or not the current action is an update or some other action -- "insert" or "delete" for example.

ARG645
Tera Guru

To explain this, we first need to know self-executable functions in Javascript. The parameter passing in a self-executable function is defined in the bottom portion of it. 

(function(param1, param2, param3) {
   if(param3){//True
     gs.log(param1);//Eggs
     gs.log(param2);//Cheese
   }
})("eggs","cheese",true);

 

The script you found, is setting isUpdate to true based on the action parameter. it doesn't mean the script won't execute if it's not an update operation, the answer really depends on how the script is defined inside the function.

By the way, where did you find this code? and can you post the function body?

Thank you,

Aman Gurram

Please mark the answer correct/helpful if applicable!