What is difference between Define and Require function in Netsuite SuiteScript 2.0

Define Function:

When define() function is used then it loads all dependencies before it executes any logic.

 it load all dependencies when script execute , 

define() can not be used when developer want to use NetSuite Debugger. 

Require Function :

Define Function is also used to load modules but dependencies will not get loaded untill needed. 

Main difference is that if developer want to use NetSuite Debugger then developer should use require() 

function because NetSuite Debugger cannot step though a define() function.

Comments

  1. What is the ideal situation to work on ?

    ReplyDelete
    Replies
    1. In Suite Script 2.0, developers can create their custom modules too.
      These custom module are same what developer used to do for library files.
      Now we have 2 kind of module, one is standard and another one is custom, so
      If we have custom module , and there is dependency on the functions, variables or formula's then we have to use define function, so that script will load the module and then use .

      ON other hand if we don't want script to load before then we have to do specify require, this function will also load the module when first reference to module is found in script.

      Also in define function we can use return , so only define can be used for custom module. We can not use require for custom module.

      Please Note:

      Only use the require() Function if you want to loading an existing module. If you want to create an entry point script or a new custom module, use the define Function.

      Also as require module use progressive loading so performance will become better in Require Module.

      This is up to you which function to use if you are only using standard modules.

      Please let me know if still not so clear, I will write a post on same topic with details this weekend

      Delete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin