Skip to content

Instantly share code, notes, and snippets.

View akash-pal's full-sized avatar
🎯
Focusing

Akash Pal akash-pal

🎯
Focusing
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@akash-pal
akash-pal / app.js
Created January 6, 2019 07:31 — forked from mrzmyr/app.js
AngularJS – readmore directive
angular.module('app', [])
.filter('truncate', function () {
return function (text, length, end) {
if (isNaN(length)) {
length = 10;
}
if (end === undefined) {
end = '...';
@akash-pal
akash-pal / mixinPattern.js
Last active July 8, 2018 07:14
JavaScript Mixin Pattern
function Person(firstName,lastName){
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function(){
return this.firstName + " " + this.lastName;
}
function Superhero(firstName,lastName,powers){
@akash-pal
akash-pal / factoryPattern.js
Last active July 8, 2018 06:30
JavaScript Factory Pattern
function Bike(options){
this.wheels = 2;
this.color = options.color;
}
function Car(options){
this.wheels = 4;
this.color = options.color;
}
@akash-pal
akash-pal / commandPattern.js
Last active July 8, 2018 05:36
JavaScript Command Pattern
var name = {
fName:'aaa',
lName:'bbb',
setName:function(fName,lName){
this.fName = fName;
this.lName = lName;
},
getName:function(){
return this.fName + " " + this.lName;
}
@akash-pal
akash-pal / prototypeDesignPattern.js
Created July 4, 2018 18:17
JavaScript Prototype Design Pattern
function person(firstName,lastName){
this.firstName = firstName;
this.lastName = lastName;
}
person.prototype.fullName = function(){
return this.firstName + " " + this.lastName;
@akash-pal
akash-pal / ConstructorDesignPattern.js
Created July 4, 2018 18:08
JavaScript Constructor Design Pattern
function person(firstName,lastName){
this.firstName = firstName;
this.lastName = lastName;
this.fullName = function(){
return this.firstName + " " + this.lastName;
}
@akash-pal
akash-pal / ModulePattern.js
Created July 4, 2018 17:45
JavaScript Module Pattern
var personModule = (function(){
var firstName;
var lastName;
return{
setName(f,l){
firstName = f;
lastName = l;
},
@akash-pal
akash-pal / RevealingModulePattern.js
Last active July 4, 2018 17:46
JavaScript Revealing Module Pattern
var personModule = (function(){
var firstName;
var lastName;
function setName(f,l){
firstName = f;
lastName = l;
}
@akash-pal
akash-pal / singletonPattern.js
Created July 4, 2018 16:29
JavaScript Singleton Design Pattern
var singleton = (function(){
var instance;
function init(){
var name;
this.setName = function(name){
this.name = name;