1# InstanceWrap<T>
2
3This class serves as the base class for [`Napi::ObjectWrap<T>`][] and
4[`Napi::Addon<T>`][].
5
6In the case of [`Napi::Addon<T>`][] it provides the
7methods for exposing functions to JavaScript on instances of an add-on.
8
9As a base class for [`Napi::ObjectWrap<T>`][] it provides the methods for
10exposing instance methods of JavaScript objects instantiated from the JavaScript
11class corresponding to the subclass of [`Napi::ObjectWrap<T>`][].
12
13## Methods
14
15### InstanceMethod
16
17Creates a property descriptor that represents a method exposed on JavaScript
18instances of this class.
19
20```cpp
21template <typename T>
22static Napi::ClassPropertyDescriptor<T>
23Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
24                             InstanceVoidMethodCallback method,
25                             napi_property_attributes attributes = napi_default,
26                             void* data = nullptr);
27```
28
29- `[in] utf8name`: Null-terminated string that represents the name of the method
30provided by instances of the class.
31- `[in] method`: The native function that represents a method provided by the
32add-on.
33- `[in] attributes`: The attributes associated with the property. One or more of
34`napi_property_attributes`.
35- `[in] data`: User-provided data passed into the method when it is invoked.
36
37Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
38provided by instances of the class. The method must be of the form
39
40```cpp
41void MethodName(const Napi::CallbackInfo& info);
42```
43
44### InstanceMethod
45
46Creates a property descriptor that represents a method exposed on JavaScript
47instances of this class.
48
49```cpp
50template <typename T>
51static Napi::ClassPropertyDescriptor<T>
52Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
53                             InstanceMethodCallback method,
54                             napi_property_attributes attributes = napi_default,
55                             void* data = nullptr);
56```
57
58- `[in] utf8name`: Null-terminated string that represents the name of the method
59provided by instances of the class.
60- `[in] method`: The native function that represents a method provided by the
61add-on.
62- `[in] attributes`: The attributes associated with the property. One or more of
63`napi_property_attributes`.
64- `[in] data`: User-provided data passed into the method when it is invoked.
65
66Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
67provided by instances of the class. The method must be of the form
68
69```cpp
70Napi::Value MethodName(const Napi::CallbackInfo& info);
71```
72
73### InstanceMethod
74
75Creates a property descriptor that represents a method exposed on JavaScript
76instances of this class.
77
78```cpp
79template <typename T>
80static Napi::ClassPropertyDescriptor<T>
81Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
82                             InstanceVoidMethodCallback method,
83                             napi_property_attributes attributes = napi_default,
84                             void* data = nullptr);
85```
86
87- `[in] name`: JavaScript symbol that represents the name of the method provided
88by instances of the class.
89- `[in] method`: The native function that represents a method provided by the
90add-on.
91- `[in] attributes`: The attributes associated with the property. One or more of
92`napi_property_attributes`.
93- `[in] data`: User-provided data passed into the method when it is invoked.
94
95Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
96provided by instances of the class. The method must be of the form
97
98```cpp
99void MethodName(const Napi::CallbackInfo& info);
100```
101
102### InstanceMethod
103
104Creates a property descriptor that represents a method exposed on JavaScript
105instances of this class.
106
107```cpp
108template <typename T>
109static Napi::ClassPropertyDescriptor<T>
110Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
111                             InstanceMethodCallback method,
112                             napi_property_attributes attributes = napi_default,
113                             void* data = nullptr);
114```
115
116- `[in] name`: JavaScript symbol that represents the name of the method provided
117by instances of the class.
118- `[in] method`: The native function that represents a method provided by the
119add-on.
120- `[in] attributes`: The attributes associated with the property. One or more of
121`napi_property_attributes`.
122- `[in] data`: User-provided data passed into the method when it is invoked.
123
124Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
125provided by instances of the class. The method must be of the form
126
127```cpp
128Napi::Value MethodName(const Napi::CallbackInfo& info);
129```
130
131### InstanceMethod
132
133Creates a property descriptor that represents a method exposed on JavaScript
134instances of this class.
135
136```cpp
137<template typename T>
138template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
139static Napi::ClassPropertyDescriptor<T>
140Napi::InstanceWrap::InstanceMethod(const char* utf8name,
141                             napi_property_attributes attributes = napi_default,
142                             void* data = nullptr);
143```
144
145- `[in] method`: The native function that represents a method provided by the
146add-on.
147- `[in] utf8name`: Null-terminated string that represents the name of the method
148provided by instances of the class.
149- `[in] attributes`: The attributes associated with the property. One or more of
150`napi_property_attributes`.
151- `[in] data`: User-provided data passed into the method when it is invoked.
152
153Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
154provided by instances of the class. The method must be of the form
155
156```cpp
157void MethodName(const Napi::CallbackInfo& info);
158```
159
160### InstanceMethod
161
162Creates a property descriptor that represents a method exposed on JavaScript
163instances of this class.
164
165```cpp
166template <typename T>
167template <typename InstanceWrap<T>::InstanceMethodCallback method>
168static Napi::ClassPropertyDescriptor<T>
169Napi::InstanceWrap<T>::InstanceMethod(const char* utf8name,
170                             napi_property_attributes attributes = napi_default,
171                             void* data = nullptr);
172```
173
174- `[in] method`: The native function that represents a method provided by the
175add-on.
176- `[in] utf8name`: Null-terminated string that represents the name of the method
177provided by instances of the class.
178- `[in] attributes`: The attributes associated with the property. One or more of
179`napi_property_attributes`.
180- `[in] data`: User-provided data passed into the method when it is invoked.
181
182Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
183provided by instances of the class. The method must be of the form
184
185```cpp
186Napi::Value MethodName(const Napi::CallbackInfo& info);
187```
188
189### InstanceMethod
190
191Creates a property descriptor that represents a method exposed on JavaScript
192instances of this class.
193
194```cpp
195template <typename T>
196template <typename InstanceWrap<T>::InstanceVoidMethodCallback method>
197static Napi::ClassPropertyDescriptor<T>
198Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
199                             napi_property_attributes attributes = napi_default,
200                             void* data = nullptr);
201```
202
203- `[in] method`: The native function that represents a method provided by the
204add-on.
205- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
206instance method for the class.
207- `[in] attributes`: The attributes associated with the property. One or more of
208`napi_property_attributes`.
209- `[in] data`: User-provided data passed into the method when it is invoked.
210
211Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
212provided by instances of the class. The method must be of the form
213
214```cpp
215void MethodName(const Napi::CallbackInfo& info);
216```
217
218### InstanceMethod
219
220Creates a property descriptor that represents a method exposed on JavaScript
221instances of this class.
222
223```cpp
224template <typename T>
225template <InstanceWrap<T>::InstanceMethodCallback method>
226static Napi::ClassPropertyDescriptor<T>
227Napi::InstanceWrap<T>::InstanceMethod(Napi::Symbol name,
228                             napi_property_attributes attributes = napi_default,
229                             void* data = nullptr);
230```
231
232- `[in] method`: The native function that represents a method provided by the
233add-on.
234- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
235instance method for the class.
236- `[in] attributes`: The attributes associated with the property. One or more of
237`napi_property_attributes`.
238- `[in] data`: User-provided data passed into the method when it is invoked.
239
240Returns a `Napi::ClassPropertyDescriptor<T>` object that represents a method
241provided by instances of the class. The method must be of the form
242
243```cpp
244Napi::Value MethodName(const Napi::CallbackInfo& info);
245```
246
247### InstanceAccessor
248
249Creates a property descriptor that represents a property exposed on JavaScript
250instances of this class.
251
252```cpp
253template <typename T>
254static Napi::ClassPropertyDescriptor<T>
255Napi::InstanceWrap<T>::InstanceAccessor(const char* utf8name,
256                             InstanceGetterCallback getter,
257                             InstanceSetterCallback setter,
258                             napi_property_attributes attributes = napi_default,
259                             void* data = nullptr);
260```
261
262- `[in] utf8name`: Null-terminated string that represents the name of the method
263provided by instances of the class.
264- `[in] getter`: The native function to call when a get access to the property
265is performed.
266- `[in] setter`: The native function to call when a set access to the property
267is performed.
268- `[in] attributes`: The attributes associated with the property. One or more of
269`napi_property_attributes`.
270- `[in] data`: User-provided data passed into the getter or the setter when it
271is invoked.
272
273Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
274accessor property provided by instances of the class.
275
276### InstanceAccessor
277
278Creates a property descriptor that represents a property exposed on JavaScript
279instances of this class.
280
281```cpp
282template <typename T>
283static Napi::ClassPropertyDescriptor<T>
284Napi::InstanceWrap<T>::InstanceAccessor(Symbol name,
285                             InstanceGetterCallback getter,
286                             InstanceSetterCallback setter,
287                             napi_property_attributes attributes = napi_default,
288                             void* data = nullptr);
289```
290
291- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
292instance accessor.
293- `[in] getter`: The native function to call when a get access to the property of
294a JavaScript class is performed.
295- `[in] setter`: The native function to call when a set access to the property of
296a JavaScript class is performed.
297- `[in] attributes`: The attributes associated with the property. One or more of
298`napi_property_attributes`.
299- `[in] data`: User-provided data passed into the getter or the setter when it
300is invoked.
301
302Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
303accessor property provided instances of the class.
304
305### InstanceAccessor
306
307Creates a property descriptor that represents a property exposed on JavaScript
308instances of this class.
309
310```cpp
311template <typename T>
312template <typename InstanceWrap<T>::InstanceGetterCallback getter,
313          typename InstanceWrap<T>::InstanceSetterCallback setter=nullptr>
314static Napi::ClassPropertyDescriptor<T>
315Napi::InstanceWrap<T>::InstanceAccessor(const char* utf8name,
316                             napi_property_attributes attributes = napi_default,
317                             void* data = nullptr);
318```
319
320- `[in] getter`: The native function to call when a get access to the property of
321a JavaScript class is performed.
322- `[in] setter`: The native function to call when a set access to the property of
323a JavaScript class is performed.
324- `[in] utf8name`: Null-terminated string that represents the name of the method
325provided by instances of the class.
326- `[in] attributes`: The attributes associated with the property. One or more of
327`napi_property_attributes`.
328- `[in] data`: User-provided data passed into the getter or the setter when it
329is invoked.
330
331Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
332accessor property provided by instances of the class.
333
334### InstanceAccessor
335
336Creates a property descriptor that represents a property exposed on JavaScript
337instances of this class.
338
339```cpp
340template <typename T>
341template <typename InstanceWrap<T>::InstanceGetterCallback getter,
342          typename InstanceWrap<T>::InstanceSetterCallback setter=nullptr>
343static Napi::ClassPropertyDescriptor<T>
344Napi::InstanceWrap<T>::InstanceAccessor(Symbol name,
345                             napi_property_attributes attributes = napi_default,
346                             void* data = nullptr);
347```
348
349- `[in] getter`: The native function to call when a get access to the property of
350a JavaScript class is performed.
351- `[in] setter`: The native function to call when a set access to the property of
352a JavaScript class is performed.
353- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
354instance accessor.
355- `[in] attributes`: The attributes associated with the property. One or more of
356`napi_property_attributes`.
357- `[in] data`: User-provided data passed into the getter or the setter when it
358is invoked.
359
360Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
361accessor property provided by instances of the class.
362
363### InstanceValue
364
365Creates property descriptor that represents a value exposed on JavaScript
366instances of this class.
367
368```cpp
369template <typename T>
370static Napi::ClassPropertyDescriptor<T>
371Napi::InstanceWrap<T>::InstanceValue(const char* utf8name,
372                            Napi::Value value,
373                            napi_property_attributes attributes = napi_default);
374```
375
376- `[in] utf8name`: Null-terminated string that represents the name of the
377property.
378- `[in] value`: The value that's retrieved by a get access of the property.
379- `[in] attributes`: The attributes associated with the property. One or more of
380`napi_property_attributes`.
381
382Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
383value property of an add-on.
384
385### InstanceValue
386
387Creates property descriptor that represents a value exposed on JavaScript
388instances of this class.
389
390```cpp
391template <typename T>
392static Napi::ClassPropertyDescriptor<T>
393Napi::InstanceWrap<T>::InstanceValue(Symbol name,
394                            Napi::Value value,
395                            napi_property_attributes attributes = napi_default);
396```
397
398- `[in] name`: The `Napi::Symbol` object whose value is used to identify the
399name of the property.
400- `[in] value`: The value that's retrieved by a get access of the property.
401- `[in] attributes`: The attributes associated with the property. One or more of
402`napi_property_attributes`.
403
404Returns a `Napi::ClassPropertyDescriptor<T>` object that represents an instance
405value property of an add-on.
406
407[`Napi::Addon<T>`]: ./addon.md
408[`Napi::ObjectWrap<T>`]: ./object_wrap.md
409