How To Write Unmaintainable Code
thc.org
thc.org
"Optimise" JavaScript code taking advantage of the fact a function can access all local variables in the scope of the caller.
Is there a good explanation of how/why this is bad/unmaintainable practice? To me, it seems more maintainable than making an external function that requires you to pass the caller scope manually... and wouldn't a good engine make those kinds of optimizations?
For example:
function test() { console.log(arguments.callee.caller.arguments); }
function test2(a, b) { test(); }
test2('x', 2);
Will print ['x', 2]. That is horrid; it makes it so you need to know the calling context to determine the behavior (and it could be globally anywhere; in a completely different .js file or even dynamically generated). With a closure the context of a function can generally be determined by simple static code inspection.I'd say finding this article hilarious would correlate well with professional coding experience :] and also I honestly had to laugh at myself a few times reading it, clearly laid out these ideas are obvious but they can be sneaky sneaky