Posts tagged with 'JavaScript'

AbortController: the Swiss army knife of JavaScript

Most people know AbortController as the thing you use to cancel fetch requests. That's fair enough — it was literally designed for that. But AbortController has quietly become one of the most versatile tools in the JavaScript standard library. Its signal mechanism plugs into event listeners, streams, Node.js APIs, and…

Mocking Angular’s $http Promise return type

The Angular $http service provides an easy way to interact with an API endpoint. If you want to query some data, you can simply do this: var request = $http.get('/api/items'); request.success(function (data) { console.log('I have data', data); }); The request object above is an Angular HTTP promise (ng.IHttpPromise…

Create a Grunt meta-runner in TeamCity

As much as all the cool kids are now using Gulp, I'm still using Grunt for a few few automated tasks. In our current project, we're using it to compress all of our JS in the project, run the Jasmine tests through Karma, and generate test code coverage reports. As well as doing this locally, we need to be able to…

Inject CSS From Your RequireJS Module Into The Main App

We’ve been doing some work on a data display app that serves as a framework for a bunch of modules. We picked RequireJS to create the app due to its modular structure and used it with a Node.js backend to build a small app that we can now create child data modules for. Each child module needs to be fully responsible…

Post an array of objects to WebAPI using jQuery

This is quite niche but caught me out the other day. Let’s say you have a person entity: public class Person { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } } and you have a WebAPI method that takes in a group: public class UsersController : ApiController { …

Completely disable cache in Google Chrome

I like debugging JavaScript in Chrome. The console is pretty excellent for stepping through code, logging, checking for bounds events etc. The one issue that I kept running into was that of caching. As I was making changes to my JS file, I found myself having to go through a couple of menu settings every time I wanted…

Getting Started With Node.js Part 1: A Quick App

Node.js is a server platform built on Google Chrome’s JavaScript runtime. It has an event-driven, non-blocking I/O model so it’s a fast and efficient as you could want. It’s also probably a good glimpse into the future of server technology. With the server running pure JavaScript, it’s a great plaform for development…

Simple JavaScript Method Chaining

Method chaining is a way to return an object from a method call that allows for further methods to be called. It’s easier to see than to describe. Instead of this: var people = helper.getPeople(); var bob = people.find('bob'); var email = bob.getEmail(); You could do this: var email =…

Starting to write JavaScript that doesn't suck

A couple of people I've spoken to in the past few days have made comments about how much they hate JavaScript and how bad it is as a programming language. I'd agree that this is true for the code that people new to the language can sometimes create. Take this wrapper for the Google Maps API: var map; function…