by Thunderya · 7y ago · 0 comments
For example, before the transformation:
function isFooLike(x) {
return x.startsWith("foo");
}
function isBarLike(x) {
return x.startsWith("bar");
}
function bigFunction(str) {
if(isFooLike(str)) {
console.log("Foo!");
}
else if(isBarLike(str)) {
console.log("Bar!");
}
else {
console.log("Unknown!");
}
}
And then: function bigFunction(str) {
if((function(x) {
return x.startsWith("foo")
})(str)) {
console.log("Foo!");
}
else if((function(x) {
return x.startsWith("bar")
})(str)) {
console.log("Bar!");
}
else {
console.log("Unknown!");
}
}Indeed, many IDEs allow you to easily display the source code of one function at a time, by navigating to the sources of the function or by displaying it in a pop-up, but the idea I had in mind is to be able to view the source code of the function with all its dependencies at a glance.