I know this may sound a little absurd, but I'm looking for a way to define every variable within a function as a property of this
. I'm looking for any hack, any way possible to be able to have some way to track variables within a function (i.e. add them to the this
object) without having to actually preface every single variable definition with this.
. Is there a way? Is this possible with Proxy
?
function () {
// declare a variable
var hello = 'hi'
return this
}
let {hello} = function()
console.log(hello) // hi
For example this works:
function hi () { this.hello = true; return this }
hi.bind({})() // { hello: true }
What I want is a way to have all variables defined within hi
to be added to the this
object when they are defined.