1 ## JavaScript-accessible methods
3 A _template_ is a blueprint for JavaScript functions and objects in a context. You can use a template to wrap C++ functions and data structures within JavaScript objects so that they can be manipulated from JavaScript. See the V8 Embedders Guide section on [Templates](https://github.com/v8/v8/wiki/Embedder%27s-Guide#templates) for further information.
5 In order to expose functionality to JavaScript via a template, you must provide it to V8 in a form that it understands. Across the versions of V8 supported by NAN, JavaScript-accessible method signatures vary widely, NAN fully abstracts method declaration and provides you with an interface that is similar to the most recent V8 API but is backward-compatible with older versions that still use the now-deceased `v8::Argument` type.
7 * **Method argument types**
8 - <a href="#api_nan_function_callback_info"><b><code>Nan::FunctionCallbackInfo</code></b></a>
9 - <a href="#api_nan_property_callback_info"><b><code>Nan::PropertyCallbackInfo</code></b></a>
10 - <a href="#api_nan_return_value"><b><code>Nan::ReturnValue</code></b></a>
11 * **Method declarations**
12 - <a href="#api_nan_method"><b>Method declaration</b></a>
13 - <a href="#api_nan_getter"><b>Getter declaration</b></a>
14 - <a href="#api_nan_setter"><b>Setter declaration</b></a>
15 - <a href="#api_nan_property_getter"><b>Property getter declaration</b></a>
16 - <a href="#api_nan_property_setter"><b>Property setter declaration</b></a>
17 - <a href="#api_nan_property_enumerator"><b>Property enumerator declaration</b></a>
18 - <a href="#api_nan_property_deleter"><b>Property deleter declaration</b></a>
19 - <a href="#api_nan_property_query"><b>Property query declaration</b></a>
20 - <a href="#api_nan_index_getter"><b>Index getter declaration</b></a>
21 - <a href="#api_nan_index_setter"><b>Index setter declaration</b></a>
22 - <a href="#api_nan_index_enumerator"><b>Index enumerator declaration</b></a>
23 - <a href="#api_nan_index_deleter"><b>Index deleter declaration</b></a>
24 - <a href="#api_nan_index_query"><b>Index query declaration</b></a>
25 * Method and template helpers
26 - <a href="#api_nan_set_method"><b><code>Nan::SetMethod()</code></b></a>
27 - <a href="#api_nan_set_prototype_method"><b><code>Nan::SetPrototypeMethod()</code></b></a>
28 - <a href="#api_nan_set_accessor"><b><code>Nan::SetAccessor()</code></b></a>
29 - <a href="#api_nan_set_named_property_handler"><b><code>Nan::SetNamedPropertyHandler()</code></b></a>
30 - <a href="#api_nan_set_indexed_property_handler"><b><code>Nan::SetIndexedPropertyHandler()</code></b></a>
31 - <a href="#api_nan_set_template"><b><code>Nan::SetTemplate()</code></b></a>
32 - <a href="#api_nan_set_prototype_template"><b><code>Nan::SetPrototypeTemplate()</code></b></a>
33 - <a href="#api_nan_set_instance_template"><b><code>Nan::SetInstanceTemplate()</code></b></a>
34 - <a href="#api_nan_set_call_handler"><b><code>Nan::SetCallHandler()</code></b></a>
35 - <a href="#api_nan_set_call_as_function_handler"><b><code>Nan::SetCallAsFunctionHandler()</code></b></a>
37 <a name="api_nan_function_callback_info"></a>
38 ### Nan::FunctionCallbackInfo
40 `Nan::FunctionCallbackInfo` should be used in place of [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/node-8.11/dd/d0d/classv8_1_1_function_callback_info.html), even with older versions of Node where `v8::FunctionCallbackInfo` does not exist.
45 template<typename T> class FunctionCallbackInfo {
47 ReturnValue<T> GetReturnValue() const;
48 v8::Local<v8::Function> Callee(); // NOTE: Not available in NodeJS >= 10.0.0
49 v8::Local<v8::Value> Data();
50 v8::Local<v8::Object> Holder();
51 bool IsConstructCall();
53 v8::Local<v8::Value> operator[](int i) const;
54 v8::Local<v8::Object> This() const;
55 v8::Isolate *GetIsolate() const;
59 See the [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/node-8.11/dd/d0d/classv8_1_1_function_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from methods.
61 **Note:** `FunctionCallbackInfo::Callee` is removed in Node.js after `10.0.0` because it is was deprecated in V8. Consider using `info.Data()` to pass any information you need.
63 <a name="api_nan_property_callback_info"></a>
64 ### Nan::PropertyCallbackInfo
66 `Nan::PropertyCallbackInfo` should be used in place of [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/node-8.11/d7/dc5/classv8_1_1_property_callback_info.html), even with older versions of Node where `v8::PropertyCallbackInfo` does not exist.
71 template<typename T> class PropertyCallbackInfo : public PropertyCallbackInfoBase<T> {
73 ReturnValue<T> GetReturnValue() const;
74 v8::Isolate* GetIsolate() const;
75 v8::Local<v8::Value> Data() const;
76 v8::Local<v8::Object> This() const;
77 v8::Local<v8::Object> Holder() const;
81 See the [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/node-8.11/d7/dc5/classv8_1_1_property_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from property accessor methods.
83 <a name="api_nan_return_value"></a>
86 `Nan::ReturnValue` is used in place of [`v8::ReturnValue`](https://v8docs.nodesource.com/node-8.11/da/da7/classv8_1_1_return_value.html) on both [`Nan::FunctionCallbackInfo`](#api_nan_function_callback_info) and [`Nan::PropertyCallbackInfo`](#api_nan_property_callback_info) as the return type of `GetReturnValue()`.
91 void EmptyArray(const Nan::FunctionCallbackInfo<v8::Value>& info) {
92 info.GetReturnValue().Set(Nan::New<v8::Array>());
99 template<typename T> class ReturnValue {
102 template <typename S> void Set(const v8::Local<S> &handle);
103 template <typename S> void Set(const Nan::Global<S> &handle);
105 // Fast primitive setters
106 void Set(bool value);
109 void Set(uint32_t i);
111 // Fast JS primitive setters
114 void SetEmptyString();
116 // Convenience getter for isolate
117 v8::Isolate *GetIsolate() const;
121 See the documentation on [`v8::ReturnValue`](https://v8docs.nodesource.com/node-8.11/da/da7/classv8_1_1_return_value.html) for further information on this.
123 <a name="api_nan_method"></a>
124 ### Method declaration
126 JavaScript-accessible methods should be declared with the following signature to form a `Nan::FunctionCallback`:
129 typedef void(*FunctionCallback)(const FunctionCallbackInfo<v8::Value>&);
135 void MethodName(const Nan::FunctionCallbackInfo<v8::Value>& info) {
140 You do not need to declare a new `HandleScope` within a method as one is implicitly created for you.
146 class Foo : public Nan::ObjectWrap {
149 static void Bar(const Nan::FunctionCallbackInfo<v8::Value>& info);
150 static void Baz(const Nan::FunctionCallbackInfo<v8::Value>& info);
155 void Foo::Bar(const Nan::FunctionCallbackInfo<v8::Value>& info) {
159 void Foo::Baz(const Nan::FunctionCallbackInfo<v8::Value>& info) {
164 A helper macro `NAN_METHOD(methodname)` exists, compatible with NAN v1 method declarations.
166 **Example usage with `NAN_METHOD(methodname)`**
170 class Foo : public Nan::ObjectWrap {
173 static NAN_METHOD(Bar);
174 static NAN_METHOD(Baz);
179 NAN_METHOD(Foo::Bar) {
183 NAN_METHOD(Foo::Baz) {
188 Use [`Nan::SetPrototypeMethod`](#api_nan_set_prototype_method) to attach a method to a JavaScript function prototype or [`Nan::SetMethod`](#api_nan_set_method) to attach a method directly on a JavaScript object.
190 <a name="api_nan_getter"></a>
191 ### Getter declaration
193 JavaScript-accessible getters should be declared with the following signature to form a `Nan::GetterCallback`:
196 typedef void(*GetterCallback)(v8::Local<v8::String>,
197 const PropertyCallbackInfo<v8::Value>&);
203 void GetterName(v8::Local<v8::String> property,
204 const Nan::PropertyCallbackInfo<v8::Value>& info) {
209 You do not need to declare a new `HandleScope` within a getter as one is implicitly created for you.
211 A helper macro `NAN_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
213 Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors).
215 <a name="api_nan_setter"></a>
216 ### Setter declaration
218 JavaScript-accessible setters should be declared with the following signature to form a <b><code>Nan::SetterCallback</code></b>:
221 typedef void(*SetterCallback)(v8::Local<v8::String>,
222 v8::Local<v8::Value>,
223 const PropertyCallbackInfo<void>&);
229 void SetterName(v8::Local<v8::String> property,
230 v8::Local<v8::Value> value,
231 const Nan::PropertyCallbackInfo<void>& info) {
236 You do not need to declare a new `HandleScope` within a setter as one is implicitly created for you.
238 A helper macro `NAN_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
240 Also see the V8 Embedders Guide documentation on [Accessors](https://developers.google.com/v8/embed#accesssors).
242 <a name="api_nan_property_getter"></a>
243 ### Property getter declaration
245 JavaScript-accessible property getters should be declared with the following signature to form a <b><code>Nan::PropertyGetterCallback</code></b>:
248 typedef void(*PropertyGetterCallback)(v8::Local<v8::String>,
249 const PropertyCallbackInfo<v8::Value>&);
255 void PropertyGetterName(v8::Local<v8::String> property,
256 const Nan::PropertyCallbackInfo<v8::Value>& info) {
261 You do not need to declare a new `HandleScope` within a property getter as one is implicitly created for you.
263 A helper macro `NAN_PROPERTY_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
265 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
267 <a name="api_nan_property_setter"></a>
268 ### Property setter declaration
270 JavaScript-accessible property setters should be declared with the following signature to form a <b><code>Nan::PropertySetterCallback</code></b>:
273 typedef void(*PropertySetterCallback)(v8::Local<v8::String>,
274 v8::Local<v8::Value>,
275 const PropertyCallbackInfo<v8::Value>&);
281 void PropertySetterName(v8::Local<v8::String> property,
282 v8::Local<v8::Value> value,
283 const Nan::PropertyCallbackInfo<v8::Value>& info);
286 You do not need to declare a new `HandleScope` within a property setter as one is implicitly created for you.
288 A helper macro `NAN_PROPERTY_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
290 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
292 <a name="api_nan_property_enumerator"></a>
293 ### Property enumerator declaration
295 JavaScript-accessible property enumerators should be declared with the following signature to form a <b><code>Nan::PropertyEnumeratorCallback</code></b>:
298 typedef void(*PropertyEnumeratorCallback)(const PropertyCallbackInfo<v8::Array>&);
304 void PropertyEnumeratorName(const Nan::PropertyCallbackInfo<v8::Array>& info);
307 You do not need to declare a new `HandleScope` within a property enumerator as one is implicitly created for you.
309 A helper macro `NAN_PROPERTY_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations.
311 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
313 <a name="api_nan_property_deleter"></a>
314 ### Property deleter declaration
316 JavaScript-accessible property deleters should be declared with the following signature to form a <b><code>Nan::PropertyDeleterCallback</code></b>:
319 typedef void(*PropertyDeleterCallback)(v8::Local<v8::String>,
320 const PropertyCallbackInfo<v8::Boolean>&);
326 void PropertyDeleterName(v8::Local<v8::String> property,
327 const Nan::PropertyCallbackInfo<v8::Boolean>& info);
330 You do not need to declare a new `HandleScope` within a property deleter as one is implicitly created for you.
332 A helper macro `NAN_PROPERTY_DELETER(methodname)` exists, compatible with NAN v1 method declarations.
334 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
336 <a name="api_nan_property_query"></a>
337 ### Property query declaration
339 JavaScript-accessible property query methods should be declared with the following signature to form a <b><code>Nan::PropertyQueryCallback</code></b>:
342 typedef void(*PropertyQueryCallback)(v8::Local<v8::String>,
343 const PropertyCallbackInfo<v8::Integer>&);
349 void PropertyQueryName(v8::Local<v8::String> property,
350 const Nan::PropertyCallbackInfo<v8::Integer>& info);
353 You do not need to declare a new `HandleScope` within a property query method as one is implicitly created for you.
355 A helper macro `NAN_PROPERTY_QUERY(methodname)` exists, compatible with NAN v1 method declarations.
357 Also see the V8 Embedders Guide documentation on named property [Interceptors](https://developers.google.com/v8/embed#interceptors).
359 <a name="api_nan_index_getter"></a>
360 ### Index getter declaration
362 JavaScript-accessible index getter methods should be declared with the following signature to form a <b><code>Nan::IndexGetterCallback</code></b>:
365 typedef void(*IndexGetterCallback)(uint32_t,
366 const PropertyCallbackInfo<v8::Value>&);
372 void IndexGetterName(uint32_t index, const PropertyCallbackInfo<v8::Value>& info);
375 You do not need to declare a new `HandleScope` within a index getter as one is implicitly created for you.
377 A helper macro `NAN_INDEX_GETTER(methodname)` exists, compatible with NAN v1 method declarations.
379 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
381 <a name="api_nan_index_setter"></a>
382 ### Index setter declaration
384 JavaScript-accessible index setter methods should be declared with the following signature to form a <b><code>Nan::IndexSetterCallback</code></b>:
387 typedef void(*IndexSetterCallback)(uint32_t,
388 v8::Local<v8::Value>,
389 const PropertyCallbackInfo<v8::Value>&);
395 void IndexSetterName(uint32_t index,
396 v8::Local<v8::Value> value,
397 const PropertyCallbackInfo<v8::Value>& info);
400 You do not need to declare a new `HandleScope` within a index setter as one is implicitly created for you.
402 A helper macro `NAN_INDEX_SETTER(methodname)` exists, compatible with NAN v1 method declarations.
404 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
406 <a name="api_nan_index_enumerator"></a>
407 ### Index enumerator declaration
409 JavaScript-accessible index enumerator methods should be declared with the following signature to form a <b><code>Nan::IndexEnumeratorCallback</code></b>:
412 typedef void(*IndexEnumeratorCallback)(const PropertyCallbackInfo<v8::Array>&);
418 void IndexEnumeratorName(const PropertyCallbackInfo<v8::Array>& info);
421 You do not need to declare a new `HandleScope` within a index enumerator as one is implicitly created for you.
423 A helper macro `NAN_INDEX_ENUMERATOR(methodname)` exists, compatible with NAN v1 method declarations.
425 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
427 <a name="api_nan_index_deleter"></a>
428 ### Index deleter declaration
430 JavaScript-accessible index deleter methods should be declared with the following signature to form a <b><code>Nan::IndexDeleterCallback</code></b>:
433 typedef void(*IndexDeleterCallback)(uint32_t,
434 const PropertyCallbackInfo<v8::Boolean>&);
440 void IndexDeleterName(uint32_t index, const PropertyCallbackInfo<v8::Boolean>& info);
443 You do not need to declare a new `HandleScope` within a index deleter as one is implicitly created for you.
445 A helper macro `NAN_INDEX_DELETER(methodname)` exists, compatible with NAN v1 method declarations.
447 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
449 <a name="api_nan_index_query"></a>
450 ### Index query declaration
452 JavaScript-accessible index query methods should be declared with the following signature to form a <b><code>Nan::IndexQueryCallback</code></b>:
455 typedef void(*IndexQueryCallback)(uint32_t,
456 const PropertyCallbackInfo<v8::Integer>&);
462 void IndexQueryName(uint32_t index, const PropertyCallbackInfo<v8::Integer>& info);
465 You do not need to declare a new `HandleScope` within a index query method as one is implicitly created for you.
467 A helper macro `NAN_INDEX_QUERY(methodname)` exists, compatible with NAN v1 method declarations.
469 Also see the V8 Embedders Guide documentation on indexed property [Interceptors](https://developers.google.com/v8/embed#interceptors).
471 <a name="api_nan_set_method"></a>
474 Sets a method with a given name directly on a JavaScript object where the method has the `Nan::FunctionCallback` signature (see <a href="#api_nan_method">Method declaration</a>).
479 void Nan::SetMethod(v8::Local<v8::Object> recv,
481 Nan::FunctionCallback callback)
482 void Nan::SetMethod(v8::Local<v8::Template> templ,
484 Nan::FunctionCallback callback)
487 <a name="api_nan_set_prototype_method"></a>
488 ### Nan::SetPrototypeMethod()
490 Sets a method with a given name on a `FunctionTemplate`'s prototype where the method has the `Nan::FunctionCallback` signature (see <a href="#api_nan_method">Method declaration</a>).
495 void Nan::SetPrototypeMethod(v8::Local<v8::FunctionTemplate> recv,
497 Nan::FunctionCallback callback)
500 <a name="api_nan_set_accessor"></a>
501 ### Nan::SetAccessor()
503 Sets getters and setters for a property with a given name on an `ObjectTemplate` or a plain `Object`. Accepts getters with the `Nan::GetterCallback` signature (see <a href="#api_nan_getter">Getter declaration</a>) and setters with the `Nan::SetterCallback` signature (see <a href="#api_nan_setter">Setter declaration</a>).
508 void SetAccessor(v8::Local<v8::ObjectTemplate> tpl,
509 v8::Local<v8::String> name,
510 Nan::GetterCallback getter,
511 Nan::SetterCallback setter = 0,
512 v8::Local<v8::Value> data = v8::Local<v8::Value>(),
513 v8::AccessControl settings = v8::DEFAULT,
514 v8::PropertyAttribute attribute = v8::None,
515 imp::Sig signature = imp::Sig());
516 bool SetAccessor(v8::Local<v8::Object> obj,
517 v8::Local<v8::String> name,
518 Nan::GetterCallback getter,
519 Nan::SetterCallback setter = 0,
520 v8::Local<v8::Value> data = v8::Local<v8::Value>(),
521 v8::AccessControl settings = v8::DEFAULT,
522 v8::PropertyAttribute attribute = v8::None)
525 See the V8 [`ObjectTemplate#SetAccessor()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#aca0ed196f8a9adb1f68b1aadb6c9cd77) and [`Object#SetAccessor()`](https://v8docs.nodesource.com/node-8.11/db/d85/classv8_1_1_object.html#ae91b3b56b357f285288c89fbddc46d1b) for further information about how to use `Nan::SetAccessor()`.
527 <a name="api_nan_set_named_property_handler"></a>
528 ### Nan::SetNamedPropertyHandler()
530 Sets named property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts:
532 * Property getters with the `Nan::PropertyGetterCallback` signature (see <a href="#api_nan_property_getter">Property getter declaration</a>)
533 * Property setters with the `Nan::PropertySetterCallback` signature (see <a href="#api_nan_property_setter">Property setter declaration</a>)
534 * Property query methods with the `Nan::PropertyQueryCallback` signature (see <a href="#api_nan_property_query">Property query declaration</a>)
535 * Property deleters with the `Nan::PropertyDeleterCallback` signature (see <a href="#api_nan_property_deleter">Property deleter declaration</a>)
536 * Property enumerators with the `Nan::PropertyEnumeratorCallback` signature (see <a href="#api_nan_property_enumerator">Property enumerator declaration</a>)
541 void SetNamedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
542 Nan::PropertyGetterCallback getter,
543 Nan::PropertySetterCallback setter = 0,
544 Nan::PropertyQueryCallback query = 0,
545 Nan::PropertyDeleterCallback deleter = 0,
546 Nan::PropertyEnumeratorCallback enumerator = 0,
547 v8::Local<v8::Value> data = v8::Local<v8::Value>())
550 See the V8 [`ObjectTemplate#SetNamedPropertyHandler()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#a33b3ebd7de641f6cc6414b7de01fc1c7) for further information about how to use `Nan::SetNamedPropertyHandler()`.
552 <a name="api_nan_set_indexed_property_handler"></a>
553 ### Nan::SetIndexedPropertyHandler()
555 Sets indexed property getters, setters, query, deleter and enumerator methods on an `ObjectTemplate`. Accepts:
557 * Indexed property getters with the `Nan::IndexGetterCallback` signature (see <a href="#api_nan_index_getter">Index getter declaration</a>)
558 * Indexed property setters with the `Nan::IndexSetterCallback` signature (see <a href="#api_nan_index_setter">Index setter declaration</a>)
559 * Indexed property query methods with the `Nan::IndexQueryCallback` signature (see <a href="#api_nan_index_query">Index query declaration</a>)
560 * Indexed property deleters with the `Nan::IndexDeleterCallback` signature (see <a href="#api_nan_index_deleter">Index deleter declaration</a>)
561 * Indexed property enumerators with the `Nan::IndexEnumeratorCallback` signature (see <a href="#api_nan_index_enumerator">Index enumerator declaration</a>)
566 void SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
567 Nan::IndexGetterCallback getter,
568 Nan::IndexSetterCallback setter = 0,
569 Nan::IndexQueryCallback query = 0,
570 Nan::IndexDeleterCallback deleter = 0,
571 Nan::IndexEnumeratorCallback enumerator = 0,
572 v8::Local<v8::Value> data = v8::Local<v8::Value>())
575 See the V8 [`ObjectTemplate#SetIndexedPropertyHandler()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#ac89f06d634add0e890452033f7d17ff1) for further information about how to use `Nan::SetIndexedPropertyHandler()`.
577 <a name="api_nan_set_template"></a>
578 ### Nan::SetTemplate()
580 Adds properties on an `Object`'s or `Function`'s template.
585 void Nan::SetTemplate(v8::Local<v8::Template> templ,
587 v8::Local<v8::Data> value);
588 void Nan::SetTemplate(v8::Local<v8::Template> templ,
589 v8::Local<v8::String> name,
590 v8::Local<v8::Data> value,
591 v8::PropertyAttribute attributes)
594 Calls the `Template`'s [`Set()`](https://v8docs.nodesource.com/node-8.11/db/df7/classv8_1_1_template.html#ae3fbaff137557aa6a0233bc7e52214ac).
596 <a name="api_nan_set_prototype_template"></a>
597 ### Nan::SetPrototypeTemplate()
599 Adds properties on an `Object`'s or `Function`'s prototype template.
604 void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
606 v8::Local<v8::Data> value);
607 void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
608 v8::Local<v8::String> name,
609 v8::Local<v8::Data> value,
610 v8::PropertyAttribute attributes)
613 Calls the `FunctionTemplate`'s _PrototypeTemplate's_ [`Set()`](https://v8docs.nodesource.com/node-8.11/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
615 <a name="api_nan_set_instance_template"></a>
616 ### Nan::SetInstanceTemplate()
618 Use to add instance properties on `FunctionTemplate`'s.
623 void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
625 v8::Local<v8::Data> value);
626 void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
627 v8::Local<v8::String> name,
628 v8::Local<v8::Data> value,
629 v8::PropertyAttribute attributes)
632 Calls the `FunctionTemplate`'s _InstanceTemplate's_ [`Set()`](https://v8docs.nodesource.com/node-8.11/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
634 <a name="api_nan_set_call_handler"></a>
635 ### Nan::SetCallHandler()
637 Set the call-handler callback for a `v8::FunctionTemplate`.
638 This callback is called whenever the function created from this FunctionTemplate is called.
643 void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
646 Calls the `FunctionTemplate`'s [`SetCallHandler()`](https://v8docs.nodesource.com/node-8.11/d8/d83/classv8_1_1_function_template.html#ab7574b298db3c27fbc2ed465c08ea2f8).
648 <a name="api_nan_set_call_as_function_handler"></a>
649 ### Nan::SetCallAsFunctionHandler()
651 Sets the callback to be used when calling instances created from the `v8::ObjectTemplate` as a function.
652 If no callback is set, instances behave like normal JavaScript objects that cannot be called as a function.
657 void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
660 Calls the `ObjectTemplate`'s [`SetCallAsFunctionHandler()`](https://v8docs.nodesource.com/node-8.11/db/d5f/classv8_1_1_object_template.html#a5e9612fc80bf6db8f2da199b9b0bd04e).