Bug Tracker

Opened 6 years ago

Closed 6 years ago

#14191 closed feature (cantfix)

Improvements to jQuery.globalEval

Reported by: brian Owned by:
Priority: undecided Milestone: None
Component: unfiled Version:
Keywords: Cc:
Blocked by: Blocking:

Description

jQuery.globalEval can definitely be useful, but why not make it even more powerful?

jsFiddle: http://jsfiddle.net/UYH97/6/

One feature that can be useful in a global eval function is a return value. This article says that jQuery "sacrifices return value for a more extensive browser support." But why stop at one when you can have both? I have been able to modify the $.globalEval function so that it provides a correct return value in all browsers - even IE 6! This is showcased in the jsFiddle demo listed above.

Another feature that I thought might be useful would be the ability to evaluate code in an iframe or external window created using window.open by implementing an optional "context" parameter. This worked in all browsers except, of course, IE. However, I was only able to test it in IE 6 and 8, both of which, I recognize, are no longer supported by the jQuery library. More info on test results can be found in the jsFiddle.

Change History (5)

comment:1 Changed 6 years ago by anonymous

Sorry - I forgot to include a link. By "this article" I mean: http://perfectionkills.com/global-eval-what-are-the-options/#global_eval_in_libraries

comment:2 Changed 6 years ago by dmethvin

Since globalEval is by definition in the global scope, I'm not sure why we even look for "use strict".

IE 6/7/8 are supported by the 1.x-master branch and we're reluctant to apply patches that cause behavior differences across the two branches.

comment:3 in reply to:  2 Changed 6 years ago by anonymous

Replying to dmethvin:

IE 6/7/8 are supported by the 1.x-master branch and we're reluctant to apply patches that cause behavior differences across the two branches.

Implementation of the return value, at least, is both useful and backward-compatible.

comment:4 in reply to:  2 Changed 6 years ago by Brian

Replying to dmethvin:

Okay, I've removed the context param from the code. The new jsFiddle can be found here: http://jsfiddle.net/UYH97/7/. It works in all browsers tested. Now, the only question is, do you want this added feature or not?

comment:5 Changed 6 years ago by markelog

Resolution: cantfix
Status: newclosed

Only execScript method could execute eval code in global namespace in oldIE. Which even mention by the kangax article that you provided –

IE<=8 executes code in the scope of a caller, as if indirect call was direct one

Note: See TracTickets for help on using tickets.