From 1331856ef167dc8d94a3355747b3177402f2b194 Mon Sep 17 00:00:00 2001 From: Kevin Eady <8634912+KevinEady@users.noreply.github.com> Date: Fri, 23 Sep 2022 17:37:21 +0200 Subject: [PATCH] doc: add HandleScope example (#1210) --- doc/handle_scope.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/handle_scope.md b/doc/handle_scope.md index aabe0eada..212344604 100644 --- a/doc/handle_scope.md +++ b/doc/handle_scope.md @@ -61,3 +61,17 @@ Napi::Env Napi::HandleScope::Env() const; ``` Returns the `Napi::Env` associated with the `Napi::HandleScope`. + +## Example + +```cpp +for (int i = 0; i < LOOP_MAX; i++) { + Napi::HandleScope scope(info.Env()); + std::string name = std::string("inner-scope") + std::to_string(i); + Napi::Value newValue = Napi::String::New(info.Env(), name.c_str()); + // do something with newValue +}; +``` + +For more details refer to the section titled [Object lifetime +management](object_lifetime_management.md).