我有一个集成到 NodeJS 中的 C++ 类,我想更改其默认对象打印
例子:
var X = new mypkg.Thing() ;
console.log( X ) ; // prints the object in std way
console.log( X.toString() ) ; // prints Diddle aye day
console.log( '' + X ) ; // prints Diddle aye day
Run Code Online (Sandbox Code Playgroud)
我在外部代码中定义了 ToString ,它有效。但我希望默认打印是相同的。
void WrappedThing::ToString( const v8::FunctionCallbackInfo<v8::Value>& args ) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set( String::NewFromUtf8( isolate, "Diddle aye day") );
}
Run Code Online (Sandbox Code Playgroud)
是否有“检查”方法可以覆盖?
TIA