Technical

Explaining the Bind Method in JavaScript

Functions in JavaScript are objects. As objects, functions possess methods, including the powerful Bind method. Bind is used for setting the this value in methods, borrowing methods of other objects and for currying functions. Bind method is primarily used to call a function with the this value set explicitly. It enables us to easily set which specific object will be bound to this when a function is invoked.

Tags: 

Javascript Code Design

Smart-designed code is much easier to maintain, optimize, and extend. There are three high-level aspects to code design that are particularly important.

- System architecture — the basic layout of the codebase. Rules that govern how various components, such as models, views, and controllers, interact with each other.
- Maintainability — how code can be improved and extended
- Reusability — how reusable are the application’s components and how easily can each implementation of a component be customized

JavaScript Closures

Closures allow JavaScript programmers to write better and concise code. A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function’s variables, and it has access to the global variables. The inner function has access not only to the outer function’s variables, but also to the outer function’s parameters.

Callback Functions in JavaScript

In JavaScript, functions are objects; that is, functions are of the type Object and they can be used in a manner like any other object since they are in fact objects themselves. They can be stored in variables, passed as arguments to functions, created within functions, and returned from functions. Because functions are objects, we can pass a function as an argument in another function and later execute that passed-in function or even return it to be executed later. This is the essence of using callback functions in JavaScript.

Iterator Specifics in C#

Iterators in C# are a very complex syntactic sugar. They take a function with yield return statements (and possible some yield break statements) and transfer it into a state machine. When you yield return, the state of the function is recorded, and execution resumes from that state the next time the iterator is called upon to produce another object. The local variables of the iterator, including the hidden this parameter, become member variables of a helper class.

Transform a Browser Into a Basic HTML Editor

The HTML5 standard has introduced a lot of new features to establish the basis for modern web. It has learned from the offerings of existing browsers and incorporated modern features. Web pages like blog postings and rich comment boxes require users to decorate their text to emphasis key points and this requires the ability to expose users to define their input in HTML form. Internet Explorer 5 had introduced a couple of attributes to help with HTML editing – contenteditable and designMode.

JavaScript Adapter Design Pattern

The Adapter design pattern converts a class interface into another one the client expects. This pattern lets classes work together otherwise they couldn't because their interfaces are incompatible. The essence of the pattern is transferring an interface (object's properties and methods) to another. A common scenario of the pattern use is when new components and modules need to be integrated to work with existing ones in an application or when part of code is refactored with improved interface but still needs to work with old parts.

JavaScript Visitor Design Pattern

The Visitor pattern defines a new operation or a set of operations on an object or a set of objects without changing the objects themselves. The new logic is implemented in a separate object defined as visitor. That is useful when building extensibility in a library or a framework. If objects provide a visit method accepting the visitor object making alterations to the current one, then there is a flawless way for clients to implement future extensions.

JavaScript Factory Design Pattern

The Factory design pattern separates object creation from the rest of code. When creation of an object is complex or a subject to a change, a factory acts as a nice mediator. However factory needs a good design as it may lead to class explosions. A simple factory is an object which implements the creation of another object, acting as a shield from the rest of application.

Tags: 

JavaScript Singleton Design Pattern

The Singleton pattern restricts an instantiation of an object to a single instance thus reducing its memory allocation and allowing a "lazy loading" on an as-needed basis. The advantages of that pattern are the reduced memory occupation, single point of access and a postponed initialization which prevents instantiation until it is required. As a disadvantage one may point out that object is hardly ever reset once instantiated and sometimes there might be hidden dependencies.

Tags: 

Pages

Subscribe to RSS - Technical