Adrenalin’s Blog

iunie 12, 2006

Javascript Eval scope namespace execution context

Categorisit la Javascript — Adrenalin @ 20:09

Here is a quote from ECMA-262:

Eval Code
When control enters an execution context for eval code, the previous active execution context, referred to as the calling context, is used to determine the scope chain, the variable object, and the this value. If there is no calling context, then initialising the scope chain, variable instantiation, and determination of the this value are performed just as for global code.

  • The scope chain is initialised to contain the same objects, in the same order, as the calling context’s
    scope chain. This includes objects added to the calling context’s scope chain by with statements and
    catch clauses.
  • Variable instantiation is performed using the calling context’s variable object and using empty
    property attributes.
  • The this value is the same as the this value of the calling context.

Also a example of code

function SomeFunc() {
  var a = ‘a local variable’;
  eval(‘alert(a)’);
}
SomeFunc();

A alert box will appear with ‘a local variable’ text.

Niciun comentariu până acum. »

nici un comentariu până acum

RSS pentru comentariile din acest post. Urmăreşte URI

Lăsați un comentariu

Bloguieşte pe WordPress.com.