Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How is this function supposed to be used?

    Hi all,
    I've just gotten a .js file and in it, at the top level, there's this function definition:


    function foo() {
    if (this.argv.length == 1) {
    // do this
    }
    }


    Now, without being defined in a class def, what is this 'this' pointed to?
    Or, can anybody tell me a way to import and then used this function? (without modifying this .js file of course)

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    That code is *NOT* for use in a browser. argv is defined for node.js

    Might also be used with other command line scripts, but not with browser-based code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    this seems to be pointing to process. typically, js files used in node use the commonJS module system, which uses the require() command to load values from the file that were published to module.exports or just exports...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •