Is it ok to remove the dollar sign in javascript function? Does it affect to functionality of the whole code inside of it?
from this
$(function() {
// code
});
to this
(function() {
// code
});
Is it ok to remove the dollar sign in javascript function? Does it affect to functionality of the whole code inside of it?
from this
$(function() {
// code
});
to this
(function() {
// code
});
From this question: What is the meaning of "$" sign in javascript
There's nothing mysterious about the use of "$" in JavaScript. $ is simply a valid JavaScript identifier.
JavaScript allows upper and lower letters, numbers, and $ and _. The $ was intended to be used for machine-generated variables (such as $0001).
Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it. In that case you use "jQuery" instead of "$". In fact, "$" is just a shortcut for "jQuery".
and
The
$
represents the jQuery Function, and is actually a shorthand alias forjQuery
. (Unlike in most languages, the$
symbol is not reserved, and may be used as a variable name.) It is typically used as a selector (i.e. a function that returns a set of elements found in the DOM).
Doing
$(function() {
// code
});
is just calling the jQuery function. It's just function, imagine something like this:
function $(callback){
//do many things
//call the callback
callback();
}
Indeed it's defined like this:
function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
// Need init if jQuery is called (just allow error to be thrown if not included)
return new jQuery.fn.init( selector, context );
}