4 ms·
Either I do not understand your point or you are walking a thin line. If a particular function can be tied to particular variable from scoping block, then the
by friendzis 10y ago
Either I do not understand your point or you are walking a thin line.
If a particular function can be tied to particular variable from scoping block, then the function is not entirely useful. On the other hand, if a function is general and has the same argument name as variable from scoping block, which is going to be passed in, mentally it is difficult to analyse the function without thinking about the variable which may shadow bugs in function. E.g. square root function may omit negative argument check, because variable from scoping block is always positive.
Instead of knowing scoping rules I advocate for distinct variable names, so scoping rules (name shadowing) do not even come into play.
- z3t4 10y agoI think the problem has to do with object oriented programming and classes. Like when you have an Apple that inherits from Fruit, witch later starts looking like a Banana. With prototype you do not have that problem as you copy-paste code instead of couple code. When you rename a variable and have to search more then one function or file, then there are bigger problems with your design, because you are basically using a global variable, even though it's praised as a module. Now does your refactor tool also fix documentation and other peoples code that depends on yours ? function Person(name) { var person = this; person.name = name; } var person = new Person("Jon Doe"); alert("Welcome " + person.name); person.name = "Harry Houdini"; // ES6 example: var messages = people.map( person => person.name += " is a rock star" )