Last active
March 24, 2017 18:20
-
-
Save ben-ng/d2643db8a6fdda23fd6b0fa787971236 to your computer and use it in GitHub Desktop.
Salesforce Marketing Cloud closure scope bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() { | |
function boom() { | |
Write('Boom'); | |
}; | |
function bar () { | |
function baz() { | |
boom(); // Fails here, "boom" can't be found | |
}; | |
return baz; | |
}; | |
return bar(); | |
} | |
foo()(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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