This topic contains 1 reply, has 0 voices, and was last updated by erictgrubaugh 7 years, 10 months ago.

  • Author
    Posts
  • #1307

    JohnCCole

    Recently I had an un-expected behaviour happen. I had created a custom module using the define statement which was then used in a client side script. Below is simplified version of the custom module.

    Code:
    define([],
    function() {
    validateDate=function(dt){
    return dt.getMonth()==0;//Just for illustration purposes we’re in January
    };
    return {
    isJanuary: function(dt){
    return this.validateDate(dt);
    }
    };
    });
    The validateDate function was defined incorrectly. it should have been

    Code:
    function validateDate
    what really surprised me was that validateDate = function() .. actually overwrote or broke a NetSuite global client side function of the same name. So while I won’t make this mistake again, how did expression validateDate = function(dt)… in my custom module cause this?

    John
    This is a cached copy. Click here to see the original post.

  • #1308

    erictgrubaugh

    Because there is no `var` keyword in front of `validateDate` when you first define it, you have effectively defined `validateDate` as a global. As soon as you include this module, it will define `validateDate` in the global space, and thus will overwrite any previously defined `validateDate` reference.

You must be logged in to reply to this topic.