You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have faced a situation in which I need to make a new object in JavaScript from C++.
But, when I Get a property of some object and Set it to another object, I get these circular references in the JavaScript code while I wanted a copy (a surprising behavior which I figured out by a lot of debugging!).
Apparently, the copy constructor (Napi::Object(ref)) has no effect on the JS side.
The JavaScript solution is to use something like copy = Object.assign({}, obj_ref). I want to know if there is a C++ solution too or I need to call the same thing from C++.
The copy constructor simply means copy the reference (you can call it a pointer to the JavaScript value or anything else) but not copy the JavaScript values. This matches across many other JavaScript engines' native API design.
As far as I can tell, using existing node-api and node-addon-api the solution you proposed is the one you can use across various Node.js versions.
I'm going to close this as there has been no further discussion since the initial answer to the question. Please let us know if you feel that was not the right thing to do.
I have faced a situation in which I need to make a new object in JavaScript from C++.
But, when I
Get
a property of some object andSet
it to another object, I get these circular references in the JavaScript code while I wanted a copy (a surprising behavior which I figured out by a lot of debugging!).Apparently, the copy constructor (
Napi::Object(ref)
) has no effect on the JS side.The JavaScript solution is to use something like
copy = Object.assign({}, obj_ref)
. I want to know if there is a C++ solution too or I need to call the same thing from C++.The text was updated successfully, but these errors were encountered: