Blog by Sumana Harihareswara, Changeset founder
JavaScript and How I Learn
Hi, reader. I wrote this in 2013 and it's now more than five years old. So it may be very out of date; the world, and I, have changed a lot since I wrote it! I'm keeping this up for historical archive purposes, but the me of today may 100% disagree with what I said then. I rarely edit posts after publishing them, but if I do, I usually leave a note in italics to mark the edit and the reason. If this post is particularly offensive or breaches someone's privacy, please contact me.
From yesterday's JavaScript explorations:
"I have now discovered thatAnd now I do! My "presidential" "speech" generator is now a web page that calls upon a CSS file, jQuery, and my JavaScript to grab three buzzwords from the user, choose random items from some pre-written lists, interpolate everything appropriately into a text template, hide the input div, and display the letter to the user -- with a little footer that floats right. It's all "client-side", as the kids say.element.innerText
works in Chrome and in Epiphany but not in Firefox.""This is why you use jQuery."
Some more things I learned:
<script>
loading tags need to load up jquery.js before loading any JavaScript files that use jQuery functionality! Or else the web console says "wtf is '$'?" in more polite language ("ReferenceError: $ is not defined").
hide
and show
jQuery functionality is a pretty clear "look! jQuery demo!" signal. And now I know why: because it is cool and easy and just works! Yay .hide()
!
input
: $( "#InputIDName" ).val();
div
:
$("#divName").html("string");
At Hacker School I followed my own advice and found or made up silly and boring and helpful projects to use while learning. My current rhythm seems to be: start by working through the first few chapters of a textbook to learn basic concepts and syntax, then think up a silly project to make and start making it, then run into problems one at a time, causing me to learn idioms and libraries and gotchas from a mix of my colleagues and the Internet. Maybe someday I will come back to chapter three of the book and engage in some more spiral learning! It's nice to have a diversified portfolio.
Comments
Roan
20 Dec 2013, 14:49 p.m.
I am pretty sure the ".html" method escapes things to keep you from opening up an XSS vuln but I'm not sure and need to check. Argh escaping!
Nope! .html() is unsafe, and it's deliberately named that to communicate the fact that it expects raw HTML and is therefore unsafe (not very clear, I know; frameworks that care more about this explicitly use the words "unsafe" or "raw"). The safe version that escapes things is .text().
I'm happy to see that you thought about escaping and XSS vulnerabilities. A shocking number of people don't.