...

View Full Version : this.JSON



otnj2ee
08-21-2008, 08:55 PM
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

rnd me
08-21-2008, 11:48 PM
#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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum