• Welcome to Tux Reports: Where Penguins Fly. We hope you find the topics varied, interesting, and worthy of your time. Please become a member and join in the discussions.

Learning JavaScript


I've been around technology for many decades, yet have avoided or skipped learning certain technologies. JavaScript is an example. You might be thinking that is silly because of JavaScript's importance on the web since 2004. In my defense, my attention has been on other technologies, mainly hardware.

A thread was posted on XF2 Demo the other night which asked about JavaScript. A XenForo developer suggested to start by looking at the thread_edit.js file.

All of the XenForo .js files begin with the Immediately-Invoked Function Expression, or IIFE for short. The developers chose to use the unary ! operator instead of parentheses.

The second line is the use strict statement. This helps keep code in a context as well as catches coding errors. John Resig's article from 2009 is still a good read.

Next is the newHandler line which is registered at the end of the expression.

XF.ThreadEditForm = XF.Element.newHandler({

Most of the code lies within the parenthesis. In fact, the line after the ending of the parenthesis is the registering of the ThreadEditForm and it looks like this:

XF.Element.register('thread-edit-form', 'XF.ThreadEditForm');

Therefore, most of the operation of the code is within the parenthesis, including options, init, beforeSubmit and afterSubmit functions.

One of my last steps before writing up this article was to look at the thread_edit template. It includes the call to the thread_edit.js file. The syntax is fairly straight forward. Angle brackets start with the xf:js call and a source location wrapped in quotes.

<xf:js src="xf/thread_edit.js" />

All of the above was done Thursday night. On Saturday morning, I woke up and started watching Joe Chellman's introduction to JavaScript on Lynda.com. I was a few lessons into it when my body needed a stretch. Joe attends the monthly WordPress meetup in Los Angeles and so I've listened to him present a few times. We've also exchanged emails enough for me to trust his work.

At this point, it's more learning. There are videos to watch, code to practice, as well as tons of reading so that JavaScript is no longer a foreign entity.

Update: I've started searching through core.js to figure out how XF is defined, XF.Element is defined, and where the register returns the className ThreadEditForm.
  • Like
Reactions: robru

Blog entry information

Last update

More entries in Technology

More entries from LPH