On 11 June 2013 17:11, Stephan Beal <sgb...@googlemail.com> wrote:
> Please consider this construct:
>
> function rowCallback(dbRow){
>   // Notes below ref to this scope
> }
>
> myDbDriver.query({
>   sql:"SELECT * FROM T",
>   callback: rowCallback
> });
>
> That hypothetical code would run the given query and call the given callback
> for each row. What i would like to do here, but don't know how, is: before
> the callback is called, i would like to inject some custom variables such
> that they could be resolved unqualified in the callback. For example, let's
> extend the above callback:
>
> function rowCallback(dbRow){
>   // dbRow == Array or Object of db row data.
>   // rowNumber == the current row number
>   // colNames == Array of column names
>   // colCount == column count
>   var i;
>   for( i = 0; i < colCount; ++i ){
>     ... do something with each column ...
>     print(colNames[i]+'='+dbRow[i]);
>   }
> }
>
> How can i (or is it even possible) to inject variables this way from a
> native-level InvocationCallback before it passes on the call callback() back
> to script-land? If i can do this, the callback wouldn't need any parameters
> - all state could be injected this way. i know i could build a custom object
> with these properties and set it as the "this" for the call, but i'm looking
> for a way where the callback does not have to this.qualify each of the
> symbols (and without using the "with" keyword).

What you want is dynamic scoping, and that is definitely not possible
in JavaScript, or most other languages for that matter.

/Andreas

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


Reply via email to