So I think it's just not possible, yet I wonder... is there a way to create a function that works like this?
const someFunction=()=> console.log(a); //printing some ref that is not out of this scope;
const wrappedFn = wrapFnOnScope(someFunction,{a:"Hello World!"});
wrappedFn() // prints Hello World!
This is indeed impossible. JavaScript has lexical scope, which means the scope of the variables in your closure depends (only) on where you did define the function. It is not possible to change this afterwards.
If you want late binding, you need to use parameters in JavaScript. It might be
const someFunction = (obj) => console.log(obj.a);
someFunction({a: 'Hello World'});
// or
const wrappedFunction = () => someFunction({a: 'Hello World'});
const wrappedFunction = someFunction.bind(undefined, {a: 'Hello World'});
or using the implicit zeroth parameter this:
function someFunction() { console.log(this.a); }
someFunction.call({a: 'Hello World'});
// or
const wrappedFunction = () => someFunction.call({a: 'Hello World'});
const wrappedFunction = someFunction.bind({a: 'Hello World'});
If you insist on referring to an a variable in the someFunction, use destructuring
const someFunction = ({a}) => console.log(a);
function someFunction() { const {a} = this; console.log(a); }
or even the dreaded with statement (bad idea!), but ultimately you must do this inside the someFunction. There is no magic wrapFnOnScope.
You appear to be conflating variables and properties. A variable is a temporary name given to a value in the code. A property is a key-value pair stored inside an object.
If you want to create a function which simply extracts a certain property from an object, you can just do it like so:
const bird = { wings: 2, color: "red" };
const getColor = value => value.color;
const birdColor = getColor(bird); // "red"
Secondly, you are trying to assign arguments in advance to a function, but only to execute said function later. This can be done by wrapping the function call in an a function without arguments like so:
const a = 1;
const b = 2;
const c = 3;
const delayedApplication = () => console.log(a + b + c);
// nothing happened yet
delayedApplication();
// "6" has been logged to the console