Profound.js Function Handling

In the PJS framework, understanding the distinction between function expressions and function declarations is crucial for effective programming. Here's a breakdown of how the PJS framework handles these two types of functions:

Function Declarations

Function declarations in the PJS framework are defined using the function keyword followed by the function name and parameters. These functions operate similarly to IBMi's procedures, as they are assigned a distinct "scope". In this scenario, "scope" ensures that IBMi-related fields are created and accessible during the function's execution. While scope enables the PJS APIs to work as intended, it may also result in a performance slowdown when these functions are required to run iteratively or recursively.

function get_product(product_id) { return pjs.query(`Select * from PRODUCTSP WHERE PRID = ${product_id}`); }

Function Expressions

Function expressions, on the other hand, involve assigning a function to a variable. In the PJS framework, function expressions lack "scope," positioning them as a more lightweight alternative to function declarations. However, this lack of “scope” can also cause issues where function expressions that are not nested within function declarations do not have necessary IBMi-related fields defined.

// These functions only work if they are nested within a function declaration OR if the database being queried is not on IBMi const find_product = function(product_id) { return pjs.query(`Select * from PRODUCTSP WHERE PRID = ${product_id}`); }; const find_product_arrow = (product_id) => { return pjs.query(`Select * from PRODUCTSP WHERE PRID = ${product_id}`); };