J
JJ
Hi all
I wanted to ask a question about below code I found in a Javascript
file:
[---SNIP---]
// Action Constants
function Action() {}
// Action types, Action names
Action.Type = { ADD: 0, UPDATE: 1, CLOSE: 2 };
Action.Name = [ "add.web", "save.web", "close" ];
....(continued)...
function getActionType( iTxnCode, sStatus )
{
var iActionType;
switch( iTxnCode ) {
case DwngTxn.TpisTxCode.INCIDENT_SUBMITTAL:
if( !sStatus )
iActionType = Action.Type.ADD;
else
iActionType = Action.Type.UPDATE;
break;
....(continued)...
[---SNIP---]
The question is that the person who developed above code seems to be
creating a function like an object (correct me if I am wrong) and then
giving it two array(?) attributes "Type" and "Name" which he/she then
populates with values.
Later in the code he/she then refers to these in the expressions:
iActionType = Action.Type.ADD;
....and...
iActionType = Action.Type.UPDATE;
My question is about that I have tried to find more information on the
web about doing this but have not seen much of anything. Could anyone
give me a brief description of what is going on above and what the
benefits of above is (or is it just to keep the code clean)?
Thanks in advance,
I wanted to ask a question about below code I found in a Javascript
file:
[---SNIP---]
// Action Constants
function Action() {}
// Action types, Action names
Action.Type = { ADD: 0, UPDATE: 1, CLOSE: 2 };
Action.Name = [ "add.web", "save.web", "close" ];
....(continued)...
function getActionType( iTxnCode, sStatus )
{
var iActionType;
switch( iTxnCode ) {
case DwngTxn.TpisTxCode.INCIDENT_SUBMITTAL:
if( !sStatus )
iActionType = Action.Type.ADD;
else
iActionType = Action.Type.UPDATE;
break;
....(continued)...
[---SNIP---]
The question is that the person who developed above code seems to be
creating a function like an object (correct me if I am wrong) and then
giving it two array(?) attributes "Type" and "Name" which he/she then
populates with values.
Later in the code he/she then refers to these in the expressions:
iActionType = Action.Type.ADD;
....and...
iActionType = Action.Type.UPDATE;
My question is about that I have tried to find more information on the
web about doing this but have not seen much of anything. Could anyone
give me a brief description of what is going on above and what the
benefits of above is (or is it just to keep the code clean)?
Thanks in advance,