Wrapping a property for making a BJS-Native plugin

I am still in the mock phase for a Webaudio plugin. In WebAudio there are many AudioNode subclasses. I see many examples of calling functions, but not any places getting or setting properties.

Example, there is an AnalyserNode. It has properties, AnalyserNode - Web APIs | MDN : fftSize, frequencyBitCount (getter only), minDecibels, maxDecibels, & smoothingTimeConstant.

If it is not a function, how do you define it in c++?

1 Like

Many ways to do it.
For simple values, you can use Napi instanceValue:

For values coming from C++, use instanceAccessor:

if the setter is nullptr then it’s a readonly value.

Also, you can find implementation ‘almost’ everywhere in the repo for Setter/Getter. Like this one:

1 Like

This is documented here as well, though some of it is node-specific which can be ignored.

nodejs/node-addon-api: Module for using N-API from C++ (github.com)

1 Like