Posts

Showing posts from June, 2013

JavaScript Design Patterns

In today’s blog, we will look at a number of JavaScript design patterns and implementation of those patterns. There is not an ideal pattern or set of patterns to use in the web application we work on. Each script and web application is its own needs and we need to think about where   a pattern can offer real value to an implementation. For example, some projects may benefit from the decoupling benefits offered by the Observer pattern whilst others may simply be too small for decoupling to be a concern at all. So a firm grasp of design patterns means to identify the problems and integrate the design patterns in the application to solve those problems more easily. We will discuss the following design patterns: Constructor Pattern Module Pattern Revealing Module Pattern Singleton Pattern Observer Pattern Mediator Pattern Prototype Pattern Command Pattern Facade Pattern Factory Pattern Mixin Pattern Decorator Pattern Flyweight Pattern   The Constructor Pattern

A Recall of Design Patterns

What is a Pattern? A pattern is a reusable solution that can be applied to commonly occurring problems in software. In other words, patterns are as templates for how we solve problems that occurred during software development. Basically, design patterns have three main benefits. 1.       Design patterns helps us in preventing minor issues that can cause major problems in the application development process. Because when code is built on proven patterns, we can afford to spend less time worrying about the structure of our code and more time focusing on the quality of our overall solution. Patterns can encourage us to code in a more structured and organized fashion avoiding the need to refactor it for cleanliness purposes in the future. 2.       Patterns can provide generalized solutions which are documented in a fashion that doesn't require them to be tied to a specific problem. This generalized approach means that regardless of the application and the programming

jQuery: $.fn.extend() and $.extend()

jQuery: $.fn.extend() and $.extend()  There is a significant difference between using $.fn.extend()   and $.extend() Extend jQuery for DOM Tags. When you want to create your own method of your DOM Tag, i.e. $(element).yourfunctionname(); $(#MyCheckBox).Check(); To achieve this, you have to define: $.fn.yourfunctionname = function () {     var o = $( this [0]) // It's your element }; $.fn.extend({      Check: function (){           Return this .each( function () { this .checked = true }); } }); We can extend multiple functions in a single “$.fn.extend” block. $.fn.extend({      Check: function (){           Return this .each( function () { this .checked = true }); },      UnCheck: function (){           Return this .each( function () { this .checked = false }); } }); // Use the newly created .check() method $( "input[type='checkbox']" ).check(); Extend jQuery using your own fu