Can I override what 'this' points to?

閲覧: 24 回
最初の未読メッセージにスキップ

Carl Erik Kopseng

未読、
2013/12/13 12:03:082013/12/13
To: js...@googlegroups.com
I am trying to convert to running my headless Mocha tests in jsdom in stead of Phantom, but I have run into a problem in that "this" does not refer to window. This, for instance, breaks Modernizr, which referes to the global environment by 'this'. It would work in Node, but it seems 'this' refers to something else than 'global' when the scripts are running in jsdom.

So I was wondering if I can set 'this' to refer to something else when running the scripts?

Godmar Back

未読、
2013/12/13 12:27:072013/12/13
To: js...@googlegroups.com

Brian's contextify should provide the correct semantics for 'this', to my knowledge. Is this no longer true?  Does your version of jsdom use contextify?


On Fri, Dec 13, 2013 at 12:03 PM, Carl Erik Kopseng <carl...@gmail.com> wrote:
I am trying to convert to running my headless Mocha tests in jsdom in stead of Phantom, but I have run into a problem in that "this" does not refer to window. This, for instance, breaks Modernizr, which referes to the global environment by 'this'. It would work in Node, but it seems 'this' refers to something else than 'global' when the scripts are running in jsdom.

So I was wondering if I can set 'this' to refer to something else when running the scripts?

--
You received this message because you are subscribed to the Google Groups "jsdom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdom+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hubert Grzeskowiak

未読、
2014/10/06 11:26:262014/10/06
To: js...@googlegroups.com
Hi Carl,

"this" is a special variable that always refers to the current object instance or context. So depending on where it's used that might be something very different. In global context it usually is set to the window, so I'd try that first.

GL
Hubert Grzeskowiak
全員に返信
投稿者に返信
転送
新着メール 0 件