Context set/get syntax question

In function nodes I often use patterns like

let startup = true;
context.set('startup',startup);

or

context.set('startup',true);
let startup = context.get('startup');

As far as I can tell, these can be replaced by the single instruction,

let startup = context.set('startup',true);

but I wonder whether this is strictly cricket in terms of JS syntax and the NR implementation of context storage. Any comments?

The context.set() api does not return the value you set, so I'm not sure why that is working for you. It certainly doesn't work when I try it here.

I suspected that, so I'm as puzzled as you are. I'll try to figure out why it seems to work.

OK. I was fooling myself by checking the value with

node.warn(context.get('startup'));

instead of

node.warn(startup);

My bad. :frowning_face:

Would it be a bad idea to allow context.set() to return a value?

if it did wouldn't you want it to return a variation of 'success' or ''failed' :grin:

2 Likes