symisc / unqlite

An Embedded NoSQL, Transactional Database Engine
https://unqlite.symisc.net
Other
2.11k stars 164 forks source link

Jx9: how use "this" in json object? #169

Closed Berleoka closed 5 months ago

Berleoka commented 5 months ago

Is there support "this" in json object in Jx9 (v1.7.2)? When i try use object field in functioin its "empty" Test on this script:

function PersonCreate(string $aname)                                
{
   $person = {
     name : $aname,
     age : 21,
     PrintName : function()
     {
       print $name;        //i try  $this.name/$this[\"name\"]/$this[0]
     },    
     PrintAge : function()
     {
       print $age;
     },
   };
  return $person;
}

$p = PersonCreate(\"vasya\");
print $p                          //{"name":"vasya","age":21,"PrintName":"[lambda_1]","PrintAge":"[lambda_2]"}
print $p.name;               //vasya
print $p.age;                  //21
$p.PrintName();             //doesn't work!
$p.PrintAge();               //doesn't work!

Thanks

symisc commented 5 months ago

There is no $this concept. Under Jx9, all member fields of a given object are publicly available. Just call the target member directly. Refer to the Jx9 Language Reference Manual at: https://jx9.symisc.net/jx9_lang.html for additional information.