Initial commit
[yaffs-website] / node_modules / nan / doc / node_misc.md
1 ## Miscellaneous Node Helpers
2
3  - <a href="#api_nan_make_callback"><b><code>Nan::MakeCallback()</code></b></a>
4  - <a href="#api_nan_module_init"><b><code>NAN_MODULE_INIT()</code></b></a>
5  - <a href="#api_nan_export"><b><code>Nan::Export()</code></b></a>
6
7
8 <a name="api_nan_make_callback"></a>
9 ### Nan::MakeCallback()
10
11 Wrappers around `node::MakeCallback()` providing a consistent API across all supported versions of Node.
12
13 Use `MakeCallback()` rather than using `v8::Function#Call()` directly in order to properly process internal Node functionality including domains, async hooks, the microtask queue, and other debugging functionality.
14
15 Signatures:
16
17 ```c++
18 v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object> target,
19                                        v8::Local<v8::Function> func,
20                                        int argc,
21                                        v8::Local<v8::Value>* argv);
22 v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object> target,
23                                        v8::Local<v8::String> symbol,
24                                        int argc,
25                                        v8::Local<v8::Value>* argv);
26 v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object> target,
27                                        const char* method,
28                                        int argc,
29                                        v8::Local<v8::Value>* argv);
30 ```
31
32
33 <a name="api_nan_module_init"></a>
34 ### NAN_MODULE_INIT()
35
36 Used to define the entry point function to a Node add-on. Creates a function with a given `name` that receives a `target` object representing the equivalent of the JavaScript `exports` object.
37
38 See example below.
39
40 <a name="api_nan_export"></a>
41 ### Nan::Export()
42
43 A simple helper to register a `v8::FunctionTemplate` from a JavaScript-accessible method (see [Methods](./methods.md)) as a property on an object. Can be used in a way similar to assigning properties to `module.exports` in JavaScript.
44
45 Signature:
46
47 ```c++
48 void Export(v8::Local<v8::Object> target, const char *name, Nan::FunctionCallback f)
49 ```
50
51 Also available as the shortcut `NAN_EXPORT` macro.
52
53 Example:
54
55 ```c++
56 NAN_METHOD(Foo) {
57   ...
58 }
59
60 NAN_MODULE_INIT(Init) {
61   NAN_EXPORT(target, Foo);
62 }
63 ```