Add a property to a node file Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceWhat is the 'global' object in NodeJSDetecting an undefined object propertyHow to efficiently count the number of keys/properties of an object in JavaScript?How can I upload files asynchronously?Add table row in jQueryHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do I include a JavaScript file in another JavaScript file?Sort array of objects by string property valueIterate through object propertiesWhat's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

What to do with post with dry rot?

Choo-choo! Word trains

Why does tar appear to skip file contents when output file is /dev/null?

How to say that you spent the night with someone, you were only sleeping and nothing else?

Stop battery usage [Ubuntu 18]

Simulating Exploding Dice

Jazz greats knew nothing of modes. Why are they used to improvise on standards?

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Blender game recording at the wrong time

I'm thinking of a number

Classification of bundles, Postnikov towers, obstruction theory, local coefficients

How does modal jazz use chord progressions?

Is 1 ppb equal to 1 μg/kg?

Limit for e and 1/e

How is simplicity better than precision and clarity in prose?

What LEGO pieces have "real-world" functionality?

How to rotate it perfectly?

Why is "Captain Marvel" translated as male in Portugal?

What would be Julian Assange's expected punishment, on the current English criminal law?

Do working physicists consider Newtonian mechanics to be "falsified"?

Fishing simulator

Complexity of many constant time steps with occasional logarithmic steps

Active filter with series inductor and resistor - do these exist?

If A makes B more likely then B makes A more likely"



Add a property to a node file



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceWhat is the 'global' object in NodeJSDetecting an undefined object propertyHow to efficiently count the number of keys/properties of an object in JavaScript?How can I upload files asynchronously?Add table row in jQueryHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do I include a JavaScript file in another JavaScript file?Sort array of objects by string property valueIterate through object propertiesWhat's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















Is it possible to add a property (with get and set method) to the scope of a file without making it global? (Similar to how let or const would work for a variable declaration)



This is the code I've written so far, It can add a property to the global scope.



var propertyValue;

Object.defineProperty(global, "PropertyValue",
get: function ()
return propertyValue;
,
set: function (value)
propertyValue = value;

);

console.log(PropertyValue);


Is it possible to make the property only visible to just the file it was declared in. The same thing can be done by declaring a variable and adding all properties there.



var fileProperties;
var propertyValue;

Object.defineProperty(fileProperties, "PropertyValue",
get: function ()
return propertyValue;
,
set: function (value)
propertyValue = value;

);

console.log(fileProperties.PropertyValue);


But then I still need to type the name of that variable every time I want to get/set a property.



So is there a way to create a property that



  1. Is not fully global

  2. Can be accessed without stating the owner object

  3. Can be recognized by eslint









share|improve this question






























    4















    Is it possible to add a property (with get and set method) to the scope of a file without making it global? (Similar to how let or const would work for a variable declaration)



    This is the code I've written so far, It can add a property to the global scope.



    var propertyValue;

    Object.defineProperty(global, "PropertyValue",
    get: function ()
    return propertyValue;
    ,
    set: function (value)
    propertyValue = value;

    );

    console.log(PropertyValue);


    Is it possible to make the property only visible to just the file it was declared in. The same thing can be done by declaring a variable and adding all properties there.



    var fileProperties;
    var propertyValue;

    Object.defineProperty(fileProperties, "PropertyValue",
    get: function ()
    return propertyValue;
    ,
    set: function (value)
    propertyValue = value;

    );

    console.log(fileProperties.PropertyValue);


    But then I still need to type the name of that variable every time I want to get/set a property.



    So is there a way to create a property that



    1. Is not fully global

    2. Can be accessed without stating the owner object

    3. Can be recognized by eslint









    share|improve this question


























      4












      4








      4








      Is it possible to add a property (with get and set method) to the scope of a file without making it global? (Similar to how let or const would work for a variable declaration)



      This is the code I've written so far, It can add a property to the global scope.



      var propertyValue;

      Object.defineProperty(global, "PropertyValue",
      get: function ()
      return propertyValue;
      ,
      set: function (value)
      propertyValue = value;

      );

      console.log(PropertyValue);


      Is it possible to make the property only visible to just the file it was declared in. The same thing can be done by declaring a variable and adding all properties there.



      var fileProperties;
      var propertyValue;

      Object.defineProperty(fileProperties, "PropertyValue",
      get: function ()
      return propertyValue;
      ,
      set: function (value)
      propertyValue = value;

      );

      console.log(fileProperties.PropertyValue);


      But then I still need to type the name of that variable every time I want to get/set a property.



      So is there a way to create a property that



      1. Is not fully global

      2. Can be accessed without stating the owner object

      3. Can be recognized by eslint









      share|improve this question
















      Is it possible to add a property (with get and set method) to the scope of a file without making it global? (Similar to how let or const would work for a variable declaration)



      This is the code I've written so far, It can add a property to the global scope.



      var propertyValue;

      Object.defineProperty(global, "PropertyValue",
      get: function ()
      return propertyValue;
      ,
      set: function (value)
      propertyValue = value;

      );

      console.log(PropertyValue);


      Is it possible to make the property only visible to just the file it was declared in. The same thing can be done by declaring a variable and adding all properties there.



      var fileProperties;
      var propertyValue;

      Object.defineProperty(fileProperties, "PropertyValue",
      get: function ()
      return propertyValue;
      ,
      set: function (value)
      propertyValue = value;

      );

      console.log(fileProperties.PropertyValue);


      But then I still need to type the name of that variable every time I want to get/set a property.



      So is there a way to create a property that



      1. Is not fully global

      2. Can be accessed without stating the owner object

      3. Can be recognized by eslint






      javascript node.js properties this global






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 12:32







      nick zoum

















      asked Jun 17 '18 at 18:36









      nick zoumnick zoum

      2,72411542




      2,72411542






















          3 Answers
          3






          active

          oldest

          votes


















          2





          +50









          A property should be accessed on some object, the only possibilities for an object to be omitted in JavaScript are global properties and with statement.



          As the original code shows, this will access a property on global variable, using global variables for local tasks is a bad practice, Using global variables for local tasks is a bad practice:



          Object.defineProperty(global, "PropertyValue", ...);

          console.log(PropertyValue);


          Another way is to use with statement, which is deprecated and won't work in strict mode:



          Object.defineProperty(someObject, "PropertyValue", ...);

          with (someObject)
          console.log(PropertyValue);



          In Node, a script is evaluated in the scope of module wrapper function, this.PropertyValue refers to module.exports.PropertyValue in module scope.



          A property can be defined on export object explicitly:



          let propertyValue;

          Object.defineProperty(exports, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(exports.PropertyValue);


          PropertyValue will be available to other modules when this module is imported. There are usually no good reasons to enforce encapsulation to the point where it starts to make developer's life harder. If PropertyValue isn't intended to be used outside the module, usually it's enough to use Hungarian notation and underscore internal/private property:



          Object.defineProperty(exports, "_PropertyValue", ... );


          This way it's still available for testing.






          share|improve this answer

























          • While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

            – nick zoum
            Mar 23 at 12:33











          • Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

            – estus
            Mar 23 at 13:03


















          2














          If you want scope of variable limited to that file only use this instead of global






          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1








          share|improve this answer























          • I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

            – nick zoum
            Mar 22 at 8:16











          • well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

            – Vikash Singh
            Mar 22 at 8:37











          • You can access it directly when using global instead of this and you can do the same with window and this in a browser.

            – nick zoum
            Mar 22 at 8:54











          • Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

            – nick zoum
            Mar 22 at 9:03







          • 1





            global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

            – Vikash Singh
            Mar 25 at 5:59



















          -1














          The answer all your questions:




          1. Is not fully global.


          2. Can be accessed without stating the owner object.


          3. Can be recognized by eslint.




          is to use const or let statements.



          From the documentation of const




          Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through reassignment, and it can't be redeclared.




          From the documentation of let




          The let statement declares a block scope local variable, optionally initializing it to a value.







          share|improve this answer























          • Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

            – Mak
            Mar 22 at 1:20






          • 1





            How do you define a property (with get and set functions) using let/const?

            – nick zoum
            Mar 22 at 7:40












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50899435%2fadd-a-property-to-a-node-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2





          +50









          A property should be accessed on some object, the only possibilities for an object to be omitted in JavaScript are global properties and with statement.



          As the original code shows, this will access a property on global variable, using global variables for local tasks is a bad practice, Using global variables for local tasks is a bad practice:



          Object.defineProperty(global, "PropertyValue", ...);

          console.log(PropertyValue);


          Another way is to use with statement, which is deprecated and won't work in strict mode:



          Object.defineProperty(someObject, "PropertyValue", ...);

          with (someObject)
          console.log(PropertyValue);



          In Node, a script is evaluated in the scope of module wrapper function, this.PropertyValue refers to module.exports.PropertyValue in module scope.



          A property can be defined on export object explicitly:



          let propertyValue;

          Object.defineProperty(exports, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(exports.PropertyValue);


          PropertyValue will be available to other modules when this module is imported. There are usually no good reasons to enforce encapsulation to the point where it starts to make developer's life harder. If PropertyValue isn't intended to be used outside the module, usually it's enough to use Hungarian notation and underscore internal/private property:



          Object.defineProperty(exports, "_PropertyValue", ... );


          This way it's still available for testing.






          share|improve this answer

























          • While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

            – nick zoum
            Mar 23 at 12:33











          • Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

            – estus
            Mar 23 at 13:03















          2





          +50









          A property should be accessed on some object, the only possibilities for an object to be omitted in JavaScript are global properties and with statement.



          As the original code shows, this will access a property on global variable, using global variables for local tasks is a bad practice, Using global variables for local tasks is a bad practice:



          Object.defineProperty(global, "PropertyValue", ...);

          console.log(PropertyValue);


          Another way is to use with statement, which is deprecated and won't work in strict mode:



          Object.defineProperty(someObject, "PropertyValue", ...);

          with (someObject)
          console.log(PropertyValue);



          In Node, a script is evaluated in the scope of module wrapper function, this.PropertyValue refers to module.exports.PropertyValue in module scope.



          A property can be defined on export object explicitly:



          let propertyValue;

          Object.defineProperty(exports, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(exports.PropertyValue);


          PropertyValue will be available to other modules when this module is imported. There are usually no good reasons to enforce encapsulation to the point where it starts to make developer's life harder. If PropertyValue isn't intended to be used outside the module, usually it's enough to use Hungarian notation and underscore internal/private property:



          Object.defineProperty(exports, "_PropertyValue", ... );


          This way it's still available for testing.






          share|improve this answer

























          • While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

            – nick zoum
            Mar 23 at 12:33











          • Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

            – estus
            Mar 23 at 13:03













          2





          +50







          2





          +50



          2




          +50





          A property should be accessed on some object, the only possibilities for an object to be omitted in JavaScript are global properties and with statement.



          As the original code shows, this will access a property on global variable, using global variables for local tasks is a bad practice, Using global variables for local tasks is a bad practice:



          Object.defineProperty(global, "PropertyValue", ...);

          console.log(PropertyValue);


          Another way is to use with statement, which is deprecated and won't work in strict mode:



          Object.defineProperty(someObject, "PropertyValue", ...);

          with (someObject)
          console.log(PropertyValue);



          In Node, a script is evaluated in the scope of module wrapper function, this.PropertyValue refers to module.exports.PropertyValue in module scope.



          A property can be defined on export object explicitly:



          let propertyValue;

          Object.defineProperty(exports, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(exports.PropertyValue);


          PropertyValue will be available to other modules when this module is imported. There are usually no good reasons to enforce encapsulation to the point where it starts to make developer's life harder. If PropertyValue isn't intended to be used outside the module, usually it's enough to use Hungarian notation and underscore internal/private property:



          Object.defineProperty(exports, "_PropertyValue", ... );


          This way it's still available for testing.






          share|improve this answer















          A property should be accessed on some object, the only possibilities for an object to be omitted in JavaScript are global properties and with statement.



          As the original code shows, this will access a property on global variable, using global variables for local tasks is a bad practice, Using global variables for local tasks is a bad practice:



          Object.defineProperty(global, "PropertyValue", ...);

          console.log(PropertyValue);


          Another way is to use with statement, which is deprecated and won't work in strict mode:



          Object.defineProperty(someObject, "PropertyValue", ...);

          with (someObject)
          console.log(PropertyValue);



          In Node, a script is evaluated in the scope of module wrapper function, this.PropertyValue refers to module.exports.PropertyValue in module scope.



          A property can be defined on export object explicitly:



          let propertyValue;

          Object.defineProperty(exports, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(exports.PropertyValue);


          PropertyValue will be available to other modules when this module is imported. There are usually no good reasons to enforce encapsulation to the point where it starts to make developer's life harder. If PropertyValue isn't intended to be used outside the module, usually it's enough to use Hungarian notation and underscore internal/private property:



          Object.defineProperty(exports, "_PropertyValue", ... );


          This way it's still available for testing.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 23 at 13:00

























          answered Mar 22 at 19:53









          estusestus

          79.6k24116237




          79.6k24116237












          • While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

            – nick zoum
            Mar 23 at 12:33











          • Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

            – estus
            Mar 23 at 13:03

















          • While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

            – nick zoum
            Mar 23 at 12:33











          • Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

            – estus
            Mar 23 at 13:03
















          While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

          – nick zoum
          Mar 23 at 12:33





          While this explain how this refers to the exports object when a containing object hasn't been defined. It still doesn't answer the question. Same thing can be achieved using a new variable and without making the variable public (updated question to include example)

          – nick zoum
          Mar 23 at 12:33













          Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

          – estus
          Mar 23 at 13:03





          Yes, the question didn't state the intention clearly. No, this isn't possible. I added the explanation. A reason to use exports is that it already exists.

          – estus
          Mar 23 at 13:03













          2














          If you want scope of variable limited to that file only use this instead of global






          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1








          share|improve this answer























          • I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

            – nick zoum
            Mar 22 at 8:16











          • well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

            – Vikash Singh
            Mar 22 at 8:37











          • You can access it directly when using global instead of this and you can do the same with window and this in a browser.

            – nick zoum
            Mar 22 at 8:54











          • Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

            – nick zoum
            Mar 22 at 9:03







          • 1





            global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

            – Vikash Singh
            Mar 25 at 5:59
















          2














          If you want scope of variable limited to that file only use this instead of global






          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1








          share|improve this answer























          • I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

            – nick zoum
            Mar 22 at 8:16











          • well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

            – Vikash Singh
            Mar 22 at 8:37











          • You can access it directly when using global instead of this and you can do the same with window and this in a browser.

            – nick zoum
            Mar 22 at 8:54











          • Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

            – nick zoum
            Mar 22 at 9:03







          • 1





            global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

            – Vikash Singh
            Mar 25 at 5:59














          2












          2








          2







          If you want scope of variable limited to that file only use this instead of global






          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1








          share|improve this answer













          If you want scope of variable limited to that file only use this instead of global






          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1








          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1





          var propertyValue;

          Object.defineProperty(this, "PropertyValue",
          get: function ()
          return propertyValue;
          ,
          set: function (value)
          propertyValue = value;

          );

          console.log(this.PropertyValue); // prints undefined

          propertyValue=a:1
          console.log(this.PropertyValue) // prints a:1






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 8:06









          Vikash SinghVikash Singh

          881520




          881520












          • I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

            – nick zoum
            Mar 22 at 8:16











          • well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

            – Vikash Singh
            Mar 22 at 8:37











          • You can access it directly when using global instead of this and you can do the same with window and this in a browser.

            – nick zoum
            Mar 22 at 8:54











          • Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

            – nick zoum
            Mar 22 at 9:03







          • 1





            global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

            – Vikash Singh
            Mar 25 at 5:59


















          • I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

            – nick zoum
            Mar 22 at 8:16











          • well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

            – Vikash Singh
            Mar 22 at 8:37











          • You can access it directly when using global instead of this and you can do the same with window and this in a browser.

            – nick zoum
            Mar 22 at 8:54











          • Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

            – nick zoum
            Mar 22 at 9:03







          • 1





            global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

            – Vikash Singh
            Mar 25 at 5:59

















          I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

          – nick zoum
          Mar 22 at 8:16





          I've tried that, it can't be accessed without stating the owner object and it can't be recognized by eslint.

          – nick zoum
          Mar 22 at 8:16













          well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

          – Vikash Singh
          Mar 22 at 8:37





          well, you can't access without stating owner object because its the property of that object. In terms of es6 if you want to access some property of class you have to use class or instance of it. I think your 2nd point is hypothetical.

          – Vikash Singh
          Mar 22 at 8:37













          You can access it directly when using global instead of this and you can do the same with window and this in a browser.

          – nick zoum
          Mar 22 at 8:54





          You can access it directly when using global instead of this and you can do the same with window and this in a browser.

          – nick zoum
          Mar 22 at 8:54













          Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

          – nick zoum
          Mar 22 at 9:03






          Accessing a variable from this usually confuses most intellisenses even if you have declared it using jsdoc

          – nick zoum
          Mar 22 at 9:03





          1




          1





          global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

          – Vikash Singh
          Mar 25 at 5:59






          global variable is shared across all the files in nodejs whereas variable declared within file has scope limited that file only. I have few sources : 1. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 2. stackabuse.com/using-global-variables-in-node-js 3. stackoverflow.com/questions/43627622/… 4. medium.com/quick-code/…

          – Vikash Singh
          Mar 25 at 5:59












          -1














          The answer all your questions:




          1. Is not fully global.


          2. Can be accessed without stating the owner object.


          3. Can be recognized by eslint.




          is to use const or let statements.



          From the documentation of const




          Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through reassignment, and it can't be redeclared.




          From the documentation of let




          The let statement declares a block scope local variable, optionally initializing it to a value.







          share|improve this answer























          • Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

            – Mak
            Mar 22 at 1:20






          • 1





            How do you define a property (with get and set functions) using let/const?

            – nick zoum
            Mar 22 at 7:40
















          -1














          The answer all your questions:




          1. Is not fully global.


          2. Can be accessed without stating the owner object.


          3. Can be recognized by eslint.




          is to use const or let statements.



          From the documentation of const




          Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through reassignment, and it can't be redeclared.




          From the documentation of let




          The let statement declares a block scope local variable, optionally initializing it to a value.







          share|improve this answer























          • Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

            – Mak
            Mar 22 at 1:20






          • 1





            How do you define a property (with get and set functions) using let/const?

            – nick zoum
            Mar 22 at 7:40














          -1












          -1








          -1







          The answer all your questions:




          1. Is not fully global.


          2. Can be accessed without stating the owner object.


          3. Can be recognized by eslint.




          is to use const or let statements.



          From the documentation of const




          Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through reassignment, and it can't be redeclared.




          From the documentation of let




          The let statement declares a block scope local variable, optionally initializing it to a value.







          share|improve this answer













          The answer all your questions:




          1. Is not fully global.


          2. Can be accessed without stating the owner object.


          3. Can be recognized by eslint.




          is to use const or let statements.



          From the documentation of const




          Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through reassignment, and it can't be redeclared.




          From the documentation of let




          The let statement declares a block scope local variable, optionally initializing it to a value.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 23:00









          WebRookieWebRookie

          19713




          19713












          • Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

            – Mak
            Mar 22 at 1:20






          • 1





            How do you define a property (with get and set functions) using let/const?

            – nick zoum
            Mar 22 at 7:40


















          • Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

            – Mak
            Mar 22 at 1:20






          • 1





            How do you define a property (with get and set functions) using let/const?

            – nick zoum
            Mar 22 at 7:40

















          Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

          – Mak
          Mar 22 at 1:20





          Since you have a setter method, I would recommend using let depending the type of data you want to store. You could use a specific convention like all upper case letters in the name to denote a file property.

          – Mak
          Mar 22 at 1:20




          1




          1





          How do you define a property (with get and set functions) using let/const?

          – nick zoum
          Mar 22 at 7:40






          How do you define a property (with get and set functions) using let/const?

          – nick zoum
          Mar 22 at 7:40


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50899435%2fadd-a-property-to-a-node-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현