4 ms·
It would actually creep me out to get any other result. For his desired outcome on the ES4 command line: var message = "Hello"; var blah0 = function () {
by astrec 18y ago
It would actually creep me out to get any other result.
For his desired outcome on the ES4 command line:
var message = "Hello";
var blah0 = function () {
var x = message;
return function () {
print(x);
}
}();
message = "World!";
var blah1 = function () {
var x = message;
return function () {
print(x);
}
}();
blah0();
>> Hello
blah1();
>> World!
- andreyf 18y agovar message = "Hello"; var blah0 = function (x) { return function () { print(x); } }(message); message = "World!"; var blah1 = function (x) { return function () { print(x); } }(message); blah0(); >> Hello blah1(); >> World! Two lines shorter! Ha! (I know, I know, line count isn't everything, yours better explains scoping, etc :-P)
- astrec 18y agoHa! ^__^