Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Articles Tagged ‘javascript’

HTTP requests with the new Angular 4 HTTP Client

Tuesday, November 7th, 2017 by Servage
angular-4Angular 4.3 comes with a new way of sending HTTP requests: the HttpClient class. The older Http class can still be used and it is not deprecated, at least for now. However, HttpClient brings some new features and will likely replace the old class in the future. Let’s go through some of the features the new HttpClient has to offer. Modifying Requests with Interceptors One of the handy new features is the ability to intercept HTTP requests with interceptors. Intercepting a request means modifying it on the fly. One common use case for interceptors is to attach a session token to every request automatically to easily authenticate with an API. Interceptors are classes that ...

How JavaScript Promises Work

Sunday, October 15th, 2017 by Servage
javascript-codeA promise is an object that represents an asynchronous action that is yet to be completed. Consider an HTTP request that loads the details of a user account. If the request is sent inside a promise, your application can continue to work on other tasks while the HTTP request is sent. When it completes, a function is called where you can handle the data that was returned. Let’s have a closer look at promises and what makes them so powerful. Creating a Promise A new promise can be created with the new keyword using the Promise class. Promises are created inside a function that performs asynchronous tasks. Therefore, you could have the following ...

Building a Front End with Ember.js

Sunday, October 8th, 2017 by Servage
emberEmber.js is yet another JavaScript framework for building the UI for web applications. While there seems to be many JavaScript frameworks out there at the moment, each of them is targeted for a specific use case, or at least is more suitable for something than the others. Usually a single framework is not always the best choice for all kinds of websites and web applications. Let’s explore Ember together and figure out how it works and what types of websites benefit from it the most. Ember.js Quick Start If you have ever worked with Angular, chances are you find getting started with Ember quite easy. The process of setting up your first Ember ...

Angular 4 Best Practices

Monday, October 2nd, 2017 by Servage
angularAngular is one of the most popular front-end frameworks. Developers sometimes prefer to use their own approach when it comes to naming conventions, whitespace usage, file structure and so on. However, if every developer chooses their own path to follow, managing a single code base in a team becomes quite challenging. To solve this, Angular has a set of rules that all developers should follow when working on an Angular project. Let’s have a look at those recommendations set by the team behind Angular. File Names Let’s start with file and directory naming conventions. By following the Angular naming conventions, you can easily identify what a file does just by looking at the ...

What is Vue.js?

Tuesday, August 1st, 2017 by Servage
vueVue.js is a framework for building interactive user interfaces. It has gained quite a bit of popularity among front-end developers for being easy to use and working well in different types of projects. What is Vue.js more specifically and how does it work? Let’s find out. Vue for Views As the name might suggest, Vue.js is the V in MVC. You can use it to build the view side of your application without worrying about the rest of your technology stack because Vue.js works well with almost any type of back end. Vue utilizes the same approach with a virtual DOM as React, making it fast to render changes on a page. It is ...

Enhanced JavaScript with TypeScript

Tuesday, April 25th, 2017 by Servage
typescriptTypeScript is a relatively new programming language from Microsoft. It is a superset of JavaScript and adds some useful features to make JavaScript coding easier and less prone to errors. What does that mean and what are these useful features? Let’s find out! Static Type Checking As the name suggests, TypeScript introduces type checking. In practise this means that variables can now have a type. In typical JavaScript, all variables are created with the var keyword in ES5 and with let in ES6. The variables are automatically assigned the correct type based on what value the variable holds. This makes JavaScript a dynamically typed language. However, TypeScript is a statically typed language since ...

Modernized strings in ES6 JavaScript

Friday, April 14th, 2017 by Servage
ES6ECMAScript 6 (ES6) has brought a lot of great features to JavaScript over the years and continues to do so as the specification is being developed. One of the new features is called template strings, which is often used in for example modern Angular or React development. It allows developers to use strings in more advanced and easier ways. This includes a new way to use multi-line strings, using strings inside variables and more with a cleaner syntax. Multi-line Strings You have likely used the concatenation operator (+) or a backslash (\) to make multi-line strings in the past. While this works fine, the syntax is is not very clean and makes the ...

Scroll-based animations with WOW.js

Wednesday, March 29th, 2017 by Servage
wowjsMany websites have animations that trigger when you scroll enough to make the element visible. Today we will see how this works and how you can implement similar animations on your own website using an easy-to-use WOW.js JavaScript library together with ready-made animations from Animate.css. Getting the Required Files Since we are going to use both WOW.js and Animate.css libraries, we have to download and include them in an HTML file. Let’s start with downloading Animate.css, but first a quick introduction to the library. As the name suggests, Animate.css is an animation library built with only CSS. It allows you to animate elements using fading, sliding and many other types of animations. You ...

Code linting explained

Friday, March 17th, 2017 by Servage
codeLinting is a term you hear every now and then, but what does it mean? Linting is related to source code analysis, which is something you should do for your code as you develop. After reading this article you will be more familiar with these things. Let’s find out what linting is and how to do it with CSS, JavaScript and PHP code. Linting Explained So, what is this mysterious “linting” people are sometimes talking about? Simply put, linting is a code review method where a program automatically analyses source code to detect issues. Lint was the name given for a C program that was used for this type of code analysis decades ...

Using Underscore.js for data manipulation

Monday, March 6th, 2017 by Servage
Screen Shot 2017-01-25 at 10.49.29Underscore is helper library written in JavaScript to make data manipulation easier. One of the most useful features in Underscore is iterating over collections like arrays and JSON objects. It makes working with data much simpler. Furthermore, Underscore can be used as a simple JavaScript template engine. Manipulating Data Let’s go through some common functions provided by the Underscore library for working with basic data. The first one is filter(). We can use this function to filter data from a collection, such as an array. Consider an example where we have a list of user ages. We want to find out how many of the users are over 50. ...