重新分配函数参数中定义的变量时,我需要使用'var'吗? [英] Javascript - Do I need to use 'var' when reassigning a variable defined in the function's parameters?

查看:46
本文介绍了重新分配函数参数中定义的变量时,我需要使用'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:

第5行字符16处的问题,已经定义了 someVar .

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆