Posts filed under the 'JavaScriptLessons' category


JavaScript: fast floor of numeric values using the tilde operator

OK, put this one in the completely weird bucket. It works, but damn it’s obscure. […]

READ MORE

JavaScript: Unit testing asynchronous functions

In a previous blog post, I talked about the QUnit unit testing library for JavaScript. In that post, I showed how to use it with a date library I was messing around with. If I were you I would review that previous blog post; it will help in what’s to come. […]

READ MORE

JavaScript: Using the shift method on the arguments array

In my webinar today on reading jQuery source code, I was talking about the extend method. I started out by talking about what a typical extend method would do before going onto the jQuery-specific one. […]

READ MORE

JavaScript for C# developers: callbacks (part III)

In the previous two installments (one, two) we explored the use of callbacks through creating a mapp function for arrays (so called because the latest JavaScripts have a native map method already), and through creating a mapAsync function where the work is done asynchronously rather than serially. The reason for this was so that we could avoid triggering the browser’s “script running a long time” warning and, also, more importantly, provide the user with a responsive UI. […]

READ MORE

JavaScript for C# developers: callbacks (part II)

Last time, we wrote a map method for arrays (which I had to call mapp, so that we didn’t clash with the native version present in many browsers). To use the map method, you have to provide a callback function that would be called for every element in the array. […]

READ MORE

JavaScript for C# developers: callbacks (part I)

As I’ve said pretty much from the very start of this series: functions are objects. You can pass them around in variables, pass them into functions as parameters, return them from functions, the whole nine yards. When you pass a function into another where it will be called, it’s generally known as a callback. […]

READ MORE

JavaScript: Using a constructor without new

In my previous blog post on the subject of constructor functions, I mentioned that there is a convention in JavaScript to name constructor functions with an initial capital letter and ordinary functions with an initial lowercase letter. This way, since the language doesn’t stop you from using a constructor as an ordinary function, there is at least some kind of “warning” that you may be using a constructor and therefore need to use new. […]

READ MORE

A JavaScript tip that’s jarring: remove falsy elements from array

Elijah Manor tweeted a link today for learnjs, a reader-supported site that provides tutorial videos on writing JavaScript. A pretty good resource to have to be sure, but there was one video there that brought me up short. […]

READ MORE

JavaScript for C# developers: writing a library (part 4)

Last time, I’d completed the cookie code. Well, “completed” in the sense of written it, but I now have to think about testing it. The writers of jQuery use a testing library called QUnit for their testing, so that’s what I’ll do too. […]

READ MORE

JavaScript for C# developers: writing a library (part 3)

Now that we created a rudimentary date library in part 2, it’s time to move back to the cookie code. […]

READ MORE