3 ms·
Interesting project, I went and looked at the [1] npm module "lib" (side note: well done, you guys must have bought it as it was first published 9 years ago) I
by gitgud 7y ago
Interesting project, I went and looked at the [1] npm module "lib" (side note: well done, you guys must have bought it as it was first published 9 years ago)
I saw in the API that you reference in the following manner, which stunned me!
const lib = require('lib');
lib.yourUsername.hostStatus(...)
How could you have a dynamic property on a synchronous object like that?! Well it turns out in the [2] source code, you can have some kind of "anonymous getter"?
get: (target, name) => {
return LibGen(...);
}
I've never seen this before and can't find any documentation about it...
[1] https://www.npmjs.com/package/lib https://www.npmjs.com/package/lib
[2] https://github.com/stdlib/lib-node/blob/bd7cada7ae366c10e316795300078182700bd87b/lib.js#L31 https://github.com/stdlib/lib-node/blob/bd7cada7ae366c10e316...
- keithwhor 7y agoIt’s referred to as a Proxy (type of Object) and they’re relatively straightforward and a newer addition to JavaScript. :)