Closed Alsan closed 8 months ago
All extension functions have all the privileges and standing of built-in functions. So they are actually executed directly on the store instance upon which they are called.
That means, that rather than go back thru the root instance (e.g. store.set(key, encryptedVal)
) you can call set
on this
: this.set(key, encryptedVal)
.
That said, if you ever want direct access to the storage area itself, that would this._area
from within the execution context of your extension function. However, do consider that an undocumented API, not subject to semver rules. Of course, it also hasn't changed in over a decade, so it's probably safe until such time as i write a new major version. Which, given my current life, won't be soon.
So far as passing a function in as the alt parameter to get/set calls, those are for custom JSON reviver/replacer functions. So we don't call those functions for null values because we know there's no JSON to parse/stringify.
It was specifically meant to expose that feature of the JSON API thru store2, not to be a generic post-process function.
Here is my code:
As you can see, the storeage is hardcoded, not querying from the passing in interface. So, how can I get the right storage?
Another question, I found that I can pass a function as the alt parameter to the get/set method to do the same thing (something like post-process of retrieved value), not that clean but work. There's an exceptional case is when the value retrieved is null, the passing in function to the get method wouldn't be called, why?