11

This is not a duplicate of the JS library to simulate Internet Explorer? question about simulating Internet Explorer's CSS support; this is about JavaScript functions.

Does a JavaScript library exist which can simulate an environment like Internet Explorer's, whereas JavaScript functions are concerned?

Basically, it would remove/overwrite the functions not supported by older versions of IE (like indexOf, etc.) or at least force any call to them to be ignored somehow.

Effectively, what I'm looking for is something almost like the opposite of Underscore.js and which theoretically could even be used to test (in non-IE browsers) that Underscore.js is doing what it's meant to do.

Or is the amount of effort needed to simulate the environment so small that I can do it quickly myself? If so, how?


The use case I'm imagining:

Using this script to simulate an IE7 environment in Phantom.js's WebKit browser for automated (by Jenkins) JavaScript unit-testing with Jasmine / QUnit / etc (undecided).

4

2 に答える 2

7

IE7 自体ではなく、このシミュレーションをどれだけサポートしているかをテストすることになるため、これには反対することをお勧めします。IE7 エンジンはほとんど標準に準拠していますが、いくつかの癖 (ぶら下がっているコンマでの悪い反応など) と、もちろん、最新の標準から欠落している環境を除きます。これらの癖のほとんどは、他のブラウザーと一致しているか、JS で完全な JS エンジンを作成しないと簡単にエミュレートできません。詳細については、ES wiki のリストを参照してください(また、「FF/Opera/Safari: 同じ」セクションに注意してください。IE と ES の不一致を説明したくない場合があります)。

あなたの最善の策は、実際のIE7を使用することです。これは、ところで、ほとんどすべてのテストに非常に優れた自動化インターフェイスを備えているか、少なくとも、互換モードがオンになっている最新のIEバージョンです。

于 2012-07-10T10:10:54.610 に答える