18c339a94Sopenharmony_ci# External (template) 28c339a94Sopenharmony_ci 38c339a94Sopenharmony_ciClass `Napi::External<T>` inherits from class [`Napi::TypeTaggable`][]. 48c339a94Sopenharmony_ci 58c339a94Sopenharmony_ciThe `Napi::External` template class implements the ability to create a `Napi::Value` object with arbitrary C++ data. It is the user's responsibility to manage the memory for the arbitrary C++ data. 68c339a94Sopenharmony_ci 78c339a94Sopenharmony_ci`Napi::External` objects can be created with an optional Finalizer function and optional Hint value. The Finalizer function, if specified, is called when your `Napi::External` object is released by Node's garbage collector. It gives your code the opportunity to free any dynamically created data. If you specify a Hint value, it is passed to your Finalizer function. 88c339a94Sopenharmony_ci 98c339a94Sopenharmony_ciNote that `Napi::Value::IsExternal()` will return `true` for any external value. 108c339a94Sopenharmony_ciIt does not differentiate between the templated parameter `T` in 118c339a94Sopenharmony_ci`Napi::External<T>`. It is up to the addon to ensure an `Napi::External<T>` 128c339a94Sopenharmony_ciobject holds the correct `T` when retrieving the data via 138c339a94Sopenharmony_ci`Napi::External<T>::Data()`. One method to ensure an object is of a specific 148c339a94Sopenharmony_citype is through [type tags](./object.md#TypeTag). 158c339a94Sopenharmony_ci 168c339a94Sopenharmony_ci## Methods 178c339a94Sopenharmony_ci 188c339a94Sopenharmony_ci### New 198c339a94Sopenharmony_ci 208c339a94Sopenharmony_ci```cpp 218c339a94Sopenharmony_citemplate <typename T> 228c339a94Sopenharmony_cistatic Napi::External Napi::External::New(napi_env env, T* data); 238c339a94Sopenharmony_ci``` 248c339a94Sopenharmony_ci 258c339a94Sopenharmony_ci- `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object. 268c339a94Sopenharmony_ci- `[in] data`: The arbitrary C++ data to be held by the `Napi::External` object. 278c339a94Sopenharmony_ci 288c339a94Sopenharmony_ciReturns the created `Napi::External<T>` object. 298c339a94Sopenharmony_ci 308c339a94Sopenharmony_ci### New 318c339a94Sopenharmony_ci 328c339a94Sopenharmony_ci```cpp 338c339a94Sopenharmony_citemplate <typename T> 348c339a94Sopenharmony_cistatic Napi::External Napi::External::New(napi_env env, 358c339a94Sopenharmony_ci T* data, 368c339a94Sopenharmony_ci Finalizer finalizeCallback); 378c339a94Sopenharmony_ci``` 388c339a94Sopenharmony_ci 398c339a94Sopenharmony_ci- `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object. 408c339a94Sopenharmony_ci- `[in] data`: The arbitrary C++ data to be held by the `Napi::External` object. 418c339a94Sopenharmony_ci- `[in] finalizeCallback`: A function called when the `Napi::External` object is released by the garbage collector accepting a T* and returning void. 428c339a94Sopenharmony_ci 438c339a94Sopenharmony_ciReturns the created `Napi::External<T>` object. 448c339a94Sopenharmony_ci 458c339a94Sopenharmony_ci### New 468c339a94Sopenharmony_ci 478c339a94Sopenharmony_ci```cpp 488c339a94Sopenharmony_citemplate <typename T> 498c339a94Sopenharmony_cistatic Napi::External Napi::External::New(napi_env env, 508c339a94Sopenharmony_ci T* data, 518c339a94Sopenharmony_ci Finalizer finalizeCallback, 528c339a94Sopenharmony_ci Hint* finalizeHint); 538c339a94Sopenharmony_ci``` 548c339a94Sopenharmony_ci 558c339a94Sopenharmony_ci- `[in] env`: The `napi_env` environment in which to construct the `Napi::External` object. 568c339a94Sopenharmony_ci- `[in] data`: The arbitrary C++ data to be held by the `Napi::External` object. 578c339a94Sopenharmony_ci- `[in] finalizeCallback`: A function called when the `Napi::External` object is released by the garbage collector accepting T* and Hint* parameters and returning void. 588c339a94Sopenharmony_ci- `[in] finalizeHint`: A hint value passed to the `finalizeCallback` function. 598c339a94Sopenharmony_ci 608c339a94Sopenharmony_ciReturns the created `Napi::External<T>` object. 618c339a94Sopenharmony_ci 628c339a94Sopenharmony_ci### Data 638c339a94Sopenharmony_ci 648c339a94Sopenharmony_ci```cpp 658c339a94Sopenharmony_ciT* Napi::External::Data() const; 668c339a94Sopenharmony_ci``` 678c339a94Sopenharmony_ci 688c339a94Sopenharmony_ciReturns a pointer to the arbitrary C++ data held by the `Napi::External` object. 698c339a94Sopenharmony_ci 708c339a94Sopenharmony_ci[`Napi::TypeTaggable`]: ./type_taggable.md 71