Skip to content

Instantly share code, notes, and snippets.

@ben-ng ben-ng/a-repro.js
Last active Mar 24, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.