Let us dive a little deeper into promises and asynchronous programming. If you already understand how asynchronous programming works in javascript, you can jump to the promises section. However if you want to under the history behind why promises exist, then read on. Javascript Promises are a much needed feature to have. They address a problem known as callback hell, which one is bound to face if they do any kind of asynchronous programming. As a web developer, this is something you cannot run away from as the browsers internal operations are asynchronous. Asynchronous here means more than one thing is happening at a time within a browsers engine. You might also hear the term synchronous in a similar manner. It means one thing happening at a time. For example, you may have heard that javascript is synchronous. This means that when executing javascript you cannot execute multiple statements at a time. Every statement that begins to execute MUST complete before another is run. This is why you hear that javascript is single threaded. Code execution is run line by line. Read More
Archive for 2016
Ajax Demystified
I don’t know about you, but the word Ajax used to scare me. As a frontend developer, it is nearly impossible avoiding the use of Ajax in your web projects, especially if your application is of dynamic nature. So i wanted to write a post that would be a go-to resource for everything Ajax you might encounter. Well… maybe everything is a bit ambitious! but i promise that by the time you are done with this tutorial, you will have victory over the subject. This post will start from totally beginner, all the way to advanced. If you feel i have left anything out, kindly comment or point it out, so i can also learn or perhaps update this post. Here i will share everything i know about using Ajax, as it has greatly helped me in my own personal and professional work. Like all my posts, this one will be a long one. I have provided links below so you can skip to any section on this topic. I will also be updating this post with time, so do come back if a section you are interested in is not ready or not found. Below is a link to the GIT repo where you can download the sample files for this post. Ready?
https://github.com/scriptonian/ajax-demystified.git
Content List:
Prototype and Prototypal Inheritance
Content List
- Introduction
- Function Constructors and Prototypes
- Prototype Properties
- Changing a functions prototype
- Multiple Inheritance
- Using Classes to create the prototype chain
- Extending built-in Objects
Introduction
In my previous post, i mentioned that ALL javascript objects have a prototype property. This prototype property is only a reference to another object (it does not live on the object). What happens is, if you ask javascript for a property on an object and it does not find it, the prototype object will be searched for that property. If it exists, that value will get returned. If you are familiar with the concept of inheritance, then this is how it works in javascript. Meaning an object in javascript inherits from its prototype (or prototype chain). This is why inheritance in javascript is called prototypal inheritance. Inheritance has a very simple meaning, it means one object gets access to the properties and methods of another object. In javascript that would be its prototype object. Read More
How to create a WordPress Plugin (Ajax Contact Form)
WordPress is a very popular CMS (Content Management System) use to create websites. It initially started out as a blogging platform but has evolved over the years. According to built with.com, WordPress has 50% of the entire CMS market. Personally, I am a Joomla fan, but I have come to appreciate WordPress and how easy it is, and specifically its support for PHP7 and HHVM, which Joomla lacks at the moment.
To create a WordPress plugin, you must have a basic understanding of PHP. PHP is very similar to other languages such as C++ and JAVA, so knowledge of those languages can be helpful too.
In this tutorial, we will create a WordPress contact form plugin that submits using AJAX and has Google Recaptcha2 to prevent spamming.
Javascript Objects
One can think of a javascript objects as containers with collections of data in it. Each data within the collection has a property name or key, with an assigned value (key-value pairs) to it. These values can be of primitive types, functions, objects, etc. When the value of a pair is a function, we call this a method. Behind the scenes, when an object is created and properties and values/methods are added to it, the object stores references to these for later access. This means that objects can store references to other objects.
There are a few ways we can create objects in javascript. We can use object literals, constructor functions, the Object.create method and we can use ES6 classes to create objects as well. Read More