Search code examples
alasql

ALASQL: How to reference the JSON object it self (to call a function on it)?


I have the following object and I would like to call it's function.

[{a:1, fn:function(){} }]

Now I know if the object would be nested ([{a:1, b:{fn:function(){} } }]) that I could do b->fn() but how do I do it when it's direct property of the first element?

I tried just SELECT fn() FROM ... but that gives Uncaught SyntaxError: Unexpected token , (so not a proper parser error).


Solution

  • Please use _ variable. This is a pseudo-variable, which includes the record whole itself:

    SELECT _->fn() FROM ...
    

    You can see this jsFiddle example.