context keyword

an array like object to view the current context in the current function. like this

var example1 = "example";
function example() {
var example2 = "another example";
console.log(context);
}
///context:[
///{example2:"another example"}, 
///globalThis
///] 

Why? What’s your use case for a “scope object”?

Your example omits example1 as well.

I think the example output didn't include example1 because the function didn't reference it, so it isn't actually available in that context.

Hi @aliibrahim123, welcome!

This might be something you could achieve with a build-step (e.g. https://babeljs.io) if you have a particular project that requires this information at runtime.

1 Like

Yes, but it could if it used eval. If it’s about “context” then that’d be what’s potentially available, whether it’s referenced or not.

If it’s about what’s referenced, then that’s a bit different and wouldn’t include globalThis.

Right, I was thinking about how this tends to be implemented in engines where without the presence of an eval only referenced bindings are captured.