The try statement:
2037 단어 IEOperaperformancefirefoxSafari
/*
:
In JScript, the variable used to hold a caught exception is visible in the enclosing scope. The variable exists after the catch clause has finished executing but ceases to exist after the function where the catch clause was located exits.
*/
function foo()
{
try
{
throw "hello";
}
catch(x)
{
document.write(x);
}
document.write(x); // x should not be visible here } foo();
/*
Output:
IE: hellohello
FF: hello (followed by error „x is not defined‟)
Opera: same as FF
Safari: same as FF
*/
/*
:
Catch is defined as creating a new object with the caught object as a property and putting the new object at the head of the scope chain. If the caught object is a function, calling it within the catch supplies the head of the scope chain as the this value. The called function can add properties to this object. This implies that for code of this shape:
The reference to 'x' within the catch is not necessarily to the local declaration of 'x'; this gives Catch the same performance problems as with. If the call to E above were specified to supply the global object (rather than the head of the scope chain) as the this value, the performance issue evaporates and the catch variable can be treated as a local scoped to the catch clause.
*/
function foo()
{
this.x = 11;
}
x = "global.x";
try
{
throw foo;
}
catch(e)
{
document.write(x) // Should print "global.x"
e();
document.write(x) // Should add x to e // (Both IE and Firefox modify the global x)
}
document.write(x);
/*
Output:
IE: prints "global.x1111
FF: same as IE
Opera: prints "global.x11global.x"
Safari: same as Opera
*/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
KindEditor 4.1.2 ie6 loadScript bugKindEditor 버전 4.1.2 ie6 아래_loadScript 메소드 버그 소스 코드는 다음과 같습니다. 이 세그먼트 코드를 다음 코드로 변경하면 정상적으로 실행됩니다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.