Salesforce Marketing Cloud closure scope bug
function foo() { | |
function boom() { | |
Write('Boom'); | |
}; | |
function bar () { | |
function baz() { | |
boom(); // Fails here, "boom" can't be found | |
}; | |
return baz; | |
}; | |
return bar(); | |
} | |
foo()(); |
// Where you execute a closure changes its scope! | |
function foo() { | |
function boom() { | |
Write('Boom'); | |
}; | |
function bar () { | |
function baz() { | |
boom(); | |
}; | |
return baz; | |
}; | |
return bar()(); // to here, the problem goes away! | |
} | |
foo(); // If you move the second application from here... |
function foo() { | |
function boom() { | |
Write('Boom'); | |
}; | |
function bar () { | |
var boom2 = boom; // Bunny-hop to a new variable. `boom = boom` does not work. | |
function baz() { | |
boom2(); | |
}; | |
return baz; | |
}; | |
return bar(); | |
} | |
foo()(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment