Sometimes the creation of an object can be complicated and the factory pattern can be used to simplify that and hide a lot of that from our front end. Basically, the factory pattern can help us simplify object creation and create different objects based on need. in this article, we will see simple examples to understand the factory pattern in JavaScript and the advantages over the others.
Continue reading “JavaScript Factories”Blog
JavaScript Errors
In JavaScript, we have a native error constructor function which we can create instances of it by using the “new” keyword”. the instance itself doesn’t do anything but by using the “throw” keyword with the error instance, interesting things can happen.
Continue reading “JavaScript Errors”JavaScript – Object Oriented Programing
Object Oriented Programing means bringing together the data and the behavior in a single location called an object. data and behavior are the 2 main things in programs. data means the things we keep in memory and behavior means functions, the things that programs can do. This paradigm is entirely different than the functional programming paradigm that keeps a separation between the data and behavior.
Continue reading “JavaScript – Object Oriented Programing”JavaScript Super Powers – Prototypal Inheritance
Inheritance is when one object gets access to the properties and methods of another object. the classical inheritance is very verbose but the Prototypal inheritance is simple, flexible, extensible, and easy to understand. both ways are not perfect but prototypal inheritance can be very powerful.
Continue reading “JavaScript Super Powers – Prototypal Inheritance”Asynchronous JavaScript
Javascript is single-threaded, only one statement is executed at a time. If something in our code is a long process it will freeze our application (block the thread) until it finishes. But as I explained in my previous articles, JavaScript does not work alone in the browser, we have the web API which is a set of features that help us run code asynchronously, a code that runs with callbacks in the background and does not freeze our application.
Continue reading “Asynchronous JavaScript”JavaScript Modules
Modules are highly self-contained and they are grouped with their specific functionality. It’s allowing them to be moved around and used by other places and even to be removed without disrupting the system as a whole.
Continue reading “JavaScript Modules”JavaScript – Functional Programing
Functional programming is all about separation of concern which object-oriented programing does as well. but in functional programming, we don’t combine the data and functions in one piece or one object like with object-oriented programming. the functions operate on well-defined data structures like arrays and objects rather than belonging to the data structure like an object.
Continue reading “JavaScript – Functional Programing”JavaScript Super Powers – Closures
When The JavaScript engine makes sure that the function has access to all the variables outside of the function, it’s a closure. closures are a feature in JavaScript also called lexical scoping. it’s a combination of 2 things: functions are first-class citizens and the lexical scope.
Continue reading “JavaScript Super Powers – Closures”JavaScript – Let’s Change This
There are times that we need to change the context of the ‘this’ keyword. since functions are objects and they have properties, we can set them and access them. with ‘call’, ‘apply’ and ‘bind’ we can change the ‘this’ keyword, and we can change the context in which the function is invoked.
Continue reading “JavaScript – Let’s Change This”JavaScript – The Story Of The 2 Phases
There are 2 phases when JavaScript starts to run, and they are called the creation phase and the execution phase. in the creation phase, JavaScript goes over the first time over the code and arranges it in memory. in the execution phase, JavaScript goes again over the code and runs it.
Continue reading “JavaScript – The Story Of The 2 Phases”