Ugly but…
In JavaScript you can do something like this:
var o = { dbRow: whatever, rowNumber: whatever, colNames: whatever, colCount:
whatever };
with (o) {
function rowCallback() {
// dbRow would be accessible without the o. prefix, etc.
}
}
On Jun 11, 2013, at 8:30 AM, Andreas Rossberg <[email protected]> wrote:
> On 11 June 2013 17:11, Stephan Beal <[email protected]> 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
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
--
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.