4 ms·
$0 tip is awesome and new tip to me. Watch the video for demo, but basically it's a reference for selected DOM element. It also appears (not mentioned in the vi
by selectnull 16y ago
$0 tip is awesome and new tip to me. Watch the video for demo, but basically it's a reference for selected DOM element. It also appears (not mentioned in the video) that $1, $2, etc references are also created for each DOM element you select in DOM tree view.
- mckoss 16y agoHave you ever notice how '$' is sometimes overridden in the developer tools console - it does not always refer to jQuery when I'm debugging in a breakpoint (thankfully, 'jQuery' always works). This confused me for quite a while. Is it something that the console is doing or is it some sort of feature of jQuery?
- catch23 16y agothe '$' is just another character from the view of the javascript interpreter. It just so happens you can use A-Z, 0-9, underscore, and the dollar sign as variable names. Libraries like Prototype & jQuery have popularized using the dollar sign as a globally accessible namespace variable, but it's nothing more than just another character.
- pyre 16y agoI think that the parent is referring to the Chrome console which has (IIRC) jQuery baked into it, even if jQuery isn't part of the actual page.
- catch23 16y agoDoes it? I don't see it in mine. HN doesn't use jQuery and when I fire up my console, the $ variable is not overwritten with a jQuery object, also there is no jQuery variable available.
- selectnull 16y agoYes, I've noticed that. It's the same in Firebug too. It definitely bugs you in debugging :) I'm not exactly sure what defines it, I think it's devtools (or firebug) itself, but it's a function that returns a dom element with id of first argument. Very annoying, although truth be told, $ and _ should have never been used in js libraries: those names were reserved for internal use in javascript.
- threepointone 16y agoCitation needed, please. I keep reading this note that $ and _ are reserved, but I haven't really seen a reference. Besides, _ and $ are not reserved keywords (unlike, say, 'class').
- selectnull 16y agoEcmascript 262, 3rd edition, section 7.6 http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf http://www.ecma-international.org/publications/files/ECMA-ST... "This standard specifies one departure from the grammar given in the Unicode standard: The dollar sign ($) and the underscore (_) are permitted anywhere in an identifier. The dollar sign is intended for use only in mechanically generated code." It was removed (or I can't find it) in 5th edition. Also, I can't find a reference for underscore.
- threepointone 16y ago[edit: read that you said it was removed in the 5th edition. makes the rest of this comment invalid, I guess] You delivered! Thank you for the effort. This what that section says - "The dollar sign ($) and the underscore (_) are permitted anywhere in an identifier. The dollar sign is intended for use only in mechanically generated code." This seems contradictory. Do they mean to say that $ (only $, not $x) is intended for use in mechanically generated code? Doesn't that make variables $0 [and so on] actually valid? And if not, then doesn't that makes $0 an invalid variable. Finally, why don't javascript interpreters throw an error when you try to name a variable $? Is there a reason they're ALL (v8, nitro, spidermonkey) lax to the ecma standard? All a little confusing, but trivial enough to ignore, I suppose... [Also, this somewhat validates my choice of using underscore.js + mixins for my code. sweet.]
- paulirish 16y agoIn Chrome DevTools, during runtime $ should always be jQuery (assuming its on the page). This isn't the case in Firebug AFAIK. I believe in both tools, at a breakpoint, $ will be the getElementById shortcut that's baked into the console API. Kind of a bummer, we're trying to work around this. You can always do `$ = jQuery;` to redefine it and you'll be good.
- selectnull 16y agoThank you for the explanation. It would be awesome if that gets "fixed". :)
- paulirish 16y agoFIXED! http://crbug.com/70969 http://crbug.com/70969 :D (it was actually fixed two weeks back. phew!)
- selectnull 16y agoAwesome. Thank you. :)
- HaloZero 16y agoAwww man, I thought I reported it first :( (My report is the duplicate listed in the ticket)