JS: Can I call a function with same scope as caller or do macro-like behavior

I often have to check whether an object exists (or more commonly, whether the object structure exists deep enough) before storing something in it. I’m tired of doing things like this:

obj ? null : obj = {};
obj[key] = value;

Since that first line is so common, it would be good to modularize it (e.g. make it a function). I’d like to be able to do this:

ensureObj(obj);
obj[key] = value;

Better yet, overcast it because I more often need something like this:

ensureObj(obj, [k1, k2, k3]);
obj[k1][k2][k3] = value;

Of course you can write a function which takes obj and does obj ? null : obj = {}; but it will never do anything for you because you can’t call ensureObj(obj) if obj doesn’t exist (similar if the obj exists, but not the deeper path).

If I could call a function and ensure it uses the same scope as where it’s called from, that should do it — it seems to me that macros are the language feature that would be just the thing for this, but I see macros don’t exist in JS, though there are packages which simulate them for you. This doesn’t (yet) work for me because my understanding is you’re not actually writing JS, but something that gets compiled into JS — which I can’t insist the team move to without a much stronger reason.

So, without using something like sweet.js, is there a way I can modularize this test/prep process?