If you want to improve the organization of your JavaScript code, consider adding JsDoc "@memberOf" before the inner function.
Check out the example below where you can find the "doValidation" and "put" functions in the outline view under the "MyNameSpace" class.
To learn more about JsDoc, visit this link:
View a snapshot from SuiteScript 2.0 RestLet integrated with RequireJS here: Snapshot from SuiteScript 2.0 RestLet. SuiteScript2.0 is integrated with RequireJS
Below is an actual code sample:
"use strict"; // Ensures that JavaScript code is executed in "strict mode"
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define(
[
'N/record', 'N/error'
],
/**
* @param {record} record
*/
function(record, error)
{
/**
* @memberOf myNameSpace
*/
function doValidation(args, argNames, methodName)
{
for (var i = 0; i < args.length; i++)
{
if (!args[i] && args[i] !== 0)
{
throw error.create(
{
name : 'MISSING_REQ_ARG',
message : 'Missing a required argument: [' + argNames[i] + '] for method: ' + methodName
});
}
}
}
// Upsert a NetSuite record from request param
/**
* @memberOf myNameSpace
*/
function put(context)
{
doValidation(
[
context.recordtype, context.id
],
[
'recordtype', 'id'
], 'PUT');
var rec = record.load(
{
type : context.recordtype,
id : context.id
});
for ( var fldName in context)
if (context.hasOwnProperty(fldName))
{
if (fldName !== 'recordtype' && fldName !== 'id')
{
rec.setValue(fldName, context[fldName]);
}
}
rec.save();
return JSON.stringify(rec);
}
return (
{
post : post
});
});