Curtis Timson

Front End & .NET Developer

Tag

javascript

Default parameters with ES6

With ES5 if you wish to set default parameters on a javascript function you would be required to check the value and supply a default if one hadn’t been set. var myFunction = function(arg1, arg2){ arg1 = arg1 || 25;… Continue Reading →

Filtering arrays in AngularJS

Previously I wrote an article on how to display data from a simple javascript array using AngularJS. Following on from that this next article will show you how to filter that same array by particular properties. In the previous article… Continue Reading →

Setting up a simple AngularJS app to display an array

AngularJS is a powerful Single-Page-Application javascript framework created by Google. The following is a simple tutorial on how to set up an AngularJS application to display a javascript array of user information. First of all we’ll start by creating our… Continue Reading →

Round to the nearest decimal

If we need round to the nearest whole number, we can use the Math.round() function to return this: Math.round(1.34234); //returns 1 However what if we need to round to a decimal place? For example 0.5. The following function can be… Continue Reading →

Mixing Revealing Module and Singleton Javascript Patterns

Until recently I’ve been using the Singleton pattern for my javascript objects. This works well as my functions are namespaced and therefore the risk of clashing object names across Javascript files is reduced. For this example I’ve created a singleton… Continue Reading →

Create a flashing tab notification page title

Page title notifications switch between the default page title and a notification message continously in order to grab the user’s attention. This is commonly used with chat applications. I’ve written a small javascript object which can be used to switch… Continue Reading →

Namespacing jQuery event handlers

If we are to attach 2 or more event handlers to an element these will become stacked and run linear in the order they were attached. For example: $(“.foo”).on(“click”, function(e){ console.log(“bar”); }); $(“.foo”).on(“click”, function(e){ console.log(“baz”); }); If .foo is then… Continue Reading →

Default negative variables to zero in javascript

If you need to default a value to 0 if its negative, you could do: var i = -45; if (i<0){ i = 0; } console.log(i); //0 However, a shorter way of doing this would be to use Math.max() passing… Continue Reading →

console.log() vs alert() when debugging

Using console.log() is a great way of getting quick results about what variables are holding what values at which point, and which areas of code are being called, without having to debug. Before javascript debugging became so accessible, one of… Continue Reading →

Reading URL hashtag values

URL hashtags were primarily used in order to position the page scroll on load to a particular element. With javascript we can access what the value of the hashtag is on page load. if (window.location.hash){ var hash = window.location.hash.substring(1); alert(“hashtag… Continue Reading →

© 2017 Curtis Timson — Powered by WordPress

Theme by Anders NorenUp ↑