[英]Why sometimes in Javascript there is the dollar sign ($arg) before function argument?
I see sometimes js snippets that are using the $ in front of the argument ($argName). 我看到有时在参数前面使用$的js片段($ argName)。
function someName(arg) {
// some code
// using arg
}
function someName($arg) {
// some code
// using $arg
}
In this js example it works either way with or without the $ in front of the arguments. 在这个js例子中,它可以使用或不使用参数前面的$。 Can anyone explaine if it has any use?
任何人都可以解释它是否有用吗?
The $
character is legal in JS identifiers, and is often used simply as a code convention to indicate that the passed parameter is already a jQuery object (as opposed to a native DOM element). $
字符在JS标识符中是合法的,并且通常仅用作代码约定来指示传递的参数已经是jQuery对象 (而不是本机DOM元素)。
This serves as a reminder that it's not necessary to re-invoke the jQuery $(param)
wrapper function on that parameter. 这提醒我们没有必要在该参数上重新调用jQuery
$(param)
包装函数。
It's also used quite a lot in Angular JS code. 它在Angular JS代码中也使用了很多。
It's sometimes used to reference an object from another library , like JQuery or AngularJS , what you're talking about here looks like AngularJs
's dependency injection to me 它有时用于引用来自另一个库的对象,比如JQuery或AngularJS,你在这里谈论的内容看起来像是
AngularJs
对我的依赖注入
UPDATE UPDATE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.