本文介绍了重新分配函数参数中定义的变量时,我需要使用'var'吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了'var'语句的许多定义,但是其中大多数都不完整(通常来自入门指南/教程).如果变量&范围已在参数列表中声明?

I've found many definitions of the 'var' statement but most of them are incomplete (usually from introductory guides/tutorials). Should I use 'var' if the variable & scope has been declared in the params list?

someFunc = function(someVar)
{
   // Is it considered good practice to use 'var', even if it is redundant? 

   var someVar = cheese;
};

推荐答案

答案是否定的,您不应该这样做.这实际上被认为是不好的做法!

The answer is no, you shouldn’t be doing this. This is actually considered a bad practice!

JS Lint 在分析您的代码示例时引发以下错误:

JS Lint throws the following error when analyzing your code example:

这篇关于重新分配函数参数中定义的变量时,我需要使用'var'吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 07:46