retro-starr Posted December 28, 2010 Share Posted December 28, 2010 Isn't JQuery just a javascript file with some nice functions pre-made for you, so how does it use $? Link to comment Share on other sites More sharing options...
Synook Posted December 28, 2010 Share Posted December 28, 2010 $ is a valid symbol name in JavaScript. Try it! $ = "blah blah";alert($); // alerts "blah blah" So the jQuery script just assigns a whole lot of stuff to the variable called $. Link to comment Share on other sites More sharing options...
boen_robot Posted December 28, 2010 Share Posted December 28, 2010 For the record, your definition of jQuery is spot on. A file with nice stuff pre-made for you is what's generally reffered to as a "library". In jQuery's case, that would be a JavaScript library, since the pre-made stuff is JavaScript functions. In, for example, a PHP context, a library could consist of a collection of nice PHP classes, functions and/or constants.A portion or a superset of such a collection that's used for a specific purpose is usually reffered to as API. A library and an API will sometimes overlap. e.g. the GD library in C is exposed to PHP via PHP's GD API. In this case we call PHP's part "API" because it's only an "interface" (a bridge if you will) to the real deal. Link to comment Share on other sites More sharing options...
retro-starr Posted December 28, 2010 Author Share Posted December 28, 2010 I thought [variable] names must begin with a letter or the underscore character. Is w3schools just giving the best practices for variables or is this really the case? Cause if it is, would browsers just be overlooking this mistake? Link to comment Share on other sites More sharing options...
jeffman Posted December 28, 2010 Share Posted December 28, 2010 Somehow $ fell through the cracks. All other non-alphanumeric characters on a US keyboard serve a programming purpose of some kind, so they would be misunderstood as variable identifiers.For what it's worth, some popular "evangelists" recommend not using _ at the start of an identifier. It is still technically correct, however. Link to comment Share on other sites More sharing options...
retro-starr Posted December 28, 2010 Author Share Posted December 28, 2010 Would it be good or OK to have bash style variables (i.e. $HOME)? Would blur the lines between many languages. Link to comment Share on other sites More sharing options...
boen_robot Posted December 28, 2010 Share Posted December 28, 2010 It's syntanctically valid, but is not considered good practice exactly because of that blur. Link to comment Share on other sites More sharing options...
retro-starr Posted December 28, 2010 Author Share Posted December 28, 2010 That sucks, I thought it'd be the other way around. Link to comment Share on other sites More sharing options...
thescientist Posted December 28, 2010 Share Posted December 28, 2010 you could also refer the jQuery $ as jQuery too, i.e. jQuery(document).ready(function(){ //stuff}); Link to comment Share on other sites More sharing options...
retro-starr Posted December 28, 2010 Author Share Posted December 28, 2010 Is that case-sensitive? I read you could set the variable to use with "var NAME=$.noConflict();". Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.