On Tuesday, October 24, 2017 at 10:25:14 AM UTC-7, Ben Noordhuis wrote: > > On Tue, Oct 24, 2017 at 6:12 PM, J Decker <d3c...@gmail.com <javascript:>> > wrote: > > > > On Tuesday, October 24, 2017 at 7:35:20 AM UTC-7, Ben Noordhuis wrote: > >> > >> On Tue, Oct 24, 2017 at 3:27 PM, J Decker <d3c...@gmail.com> wrote: > >> > Is there a way to make a C++ class that has set accessors on the > >> > prototype > >> > to get its data logged? > >> > > >> > so like > >> > var color = new Color( "white" ); > >> > console.log( color ): > >> > >> I think you are asking about the difference between > >> PropertyCallbackInfo<T>::This() and PropertyCallbackInfo<T>::Holder(). > >> The first is the instance object, the second the prototype object. > >> > >> (If it's not that, please clarify what "gets its data logged" means.) > > > > > > No... I'm just asking if there's a way to get console.log to log > > setters/getters configured on the object, similar to how it will log > > properties directly on an object. > > and re the this/holder differneces... the documentation in v8.h > describes > > this and holder pretty well now.... > > > >> > >> > >> > Also, I added a toString() method to the prototype, but apparently I > >> > have to > >> > append it to a string (as in console.log( ""+color ) } or call it > >> > explicitly... console.log( color.toString() ) > >> > >> Yes. Did you expect something else? > > > > > > Well another thread said I shouldn't have to append it to a string... I > > mean doesn't console.log attempt to convert arguments to string anyway? > I > > know it doesn't in a browser, because you get an arrow you can use to > expand > > an object... but this is using node... hmm maybe it's more of a node > issue; > > I suppose if I were using electron or nwjs I would get the object logged > > with an expansion arrow... > > Right. Yes, the console.log() in Node.js goes well beyond simple > stringification. It also doesn't print non-enumerable properties[0] or > properties from the prototype chain. > > [0] `console.log(util.inspect(obj, {showHidden: true}))` will, though. >
That could be useful thank you for the hint. Doesn't help for logging an instance of an object template. It does show the properties in an object template though.... sack.Image.colors.white is an instance of a sack.Image.Color (need to rename the internal name text). console.log( "got", util.inspect(sack.Image.colors.white, {showHidden: true}) ); got sack.Image.color {} console.log( "color:", ""+sack.Image.colors.white); color: {r:255,g:255,b:255,a:255} var x = sack.Image.Color( {r:50,g:50,b:255,a:255} ); console.log( "color:", Object.keys(Object.getPrototypeOf( x )), ""+x, x.toString() ); color: [ 'a', 'b', 'g', 'r', 'toString' ] {r:50,g:50,b:255,a:255} {r:50,g:50,b:255,a:255} console.log( "got", util.inspect(sack.Image.Color, {showHidden: true}) ); got { [Function: sack.Image.color] [length]: 0, [name]: 'sack.Image.color', [arguments]: null, [caller]: null, [prototype]: sack.Image.color { a: undefined, b: undefined, g: undefined, r: undefined, toString: { [Function: toString] [length]: 0, name]: 'toString', [arguments]: null, [caller]: null, [prototype]: [Object] }, [constructor]: [Circular] } } logging the getters though returns 'undefined' because it's logging the prototype and not an instance of the prototype ( 'this' isn't a ColorObject ) -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.