From what I understand after reading some ECMA-262 specs, global
execution context - the object where 'this' keyword points when you're
in the outermost scope - should be the 'global' object containing
built-in language global methods/objects (things like Math, isNaN and
so on), enriched with environment-specific methods/objects (such as
setTimeout, document etc in the browser).
In a browser, such object is also called 'window'.
However, in Node it looks quite strange:
[wildcard@magic-missile bookbu.js (master)]$ node
> this
{}
> require('util').inspect(this)
'{}'
> this+""
'[object global]'
... however:
> for (var i in this) { console.log(i) }
global
process
GLOBAL
root
setTimeout
setInterval
clearTimeout
clearInterval
console
Buffer
module
require
_
i
notice that we're still not seeing everythig. where's Math?
> Math
{}
> this.Math
{}
> Math === this.Math
true
> Math+""
'[object Math]'
hm. cool. 'enumerable' property from ECMAScript 5 would explain something, but:
> Object.getOwnPropertyDescriptor(this)
{ value: undefined, writable: true, enumerable: false, configurable: false }
> Object.getOwnPropertyDescriptor(Math)
>
now I'm lost. phantom objects everywhere! but hey...
> for (var i in Math) { console.log(i) }
> Math.PI
3.141592653589793
now I'm lost^2.
some objects show their members, some others don't. some of them list
their properties, some don't. it's possible to iterate over members of
some object (but not all of them), and see some of their members (but
not all of them).
anyone can help me with some explanation? I understand that Node may
not follow ECMA strictly in some cases, but it just doesn't make any
sense to me.
PS. node v0.4.0
--
Szymon Piłkowski :-: http://twitter.com/ard
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
2011/4/9 Szymon Piłkowski <szymon.p...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>
--
regards,
Oleg Slobodskoi
--------------------------------------------------------------------
Xing: https://xing.com/profile/Oleg_Slobodskoi
Twitter: https://twitter.com/oleg008
Github: https://github.com/kof