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 2 of 2

Thread: this.JSON

  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts

    this.JSON

    I have two questions:

    1)

    In the http://www.JSON.org/js.html, I saw

    if (!this.JSON) {

    JSON = function () {



    --What does the "this" represent?


    2)

    In a javascript, I can decalre a global variable in a test.js file:

    glbVar ="abc"; //Not inside a function

    --Who owns this variable (I believe there should be an owner for this variable)? If I use this.glbVar, what does the "this" represent?


    Thanks

    Scott

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    #1some ecma script implementation have no window object.
    jscript.net and jscript as a window script comes to mind.

    in those cases, you have to use "this" instead of "window".

    window is not a ecma script object, "this" is.
    i would imagine the json script is coded this way so it can run in those environments.



    #2: there is no owner, so i guess you mean "window".

    "this" is a mysterious beast for javascript newcomers.

    it means at least 4-5 different main things, and if you want to split hairs, about a dozen.

    the big ones:
    inside of a constructor function, it means the object.
    in a classic event handler, it usually means the element raising the event.
    used out in the open, it means window.
    on a prototype method, it refers to the object having the prototype.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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