Skip to content

Instantly share code, notes, and snippets.

View hwclass's full-sized avatar

Barış Güler hwclass

View GitHub Profile
@hwclass
hwclass / module
Created January 29, 2015 23:18
Sample module implementation
/*
* A module implementation to bind events and do something else independently
*/
var module = (function () {
return function (elementType, methods) {
console.log(elementType);
console.log(methods);
}
})();
@hwclass
hwclass / mixin_pattern_example
Last active August 29, 2015 14:23
Mixin pattern example in Javascript.
var Person = function (name, age) {
this.name = name;
this.age = age;
}
function extend(destination, source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
destination[k] = source[k];
}
@hwclass
hwclass / singletonPattern-Config.js
Created July 2, 2015 08:28
Singleton Pattern (Config.js)
// models/Config.js
module.exports = (function () {
return function () {
var config = {
urls : {
tabs : {
address : '/#address',
payment : '/#payment'
}
},
@hwclass
hwclass / singletonPattern-base.js
Created July 2, 2015 08:29
Singleton Pattern (base.js)
// base.js
var Config = require(‘models/Config’);
var configInstance = new Config();
var config = configInstance.getConfig();
configInstance = null;
$(‘.error).html(config.messages.errors.default);
@hwclass
hwclass / Module.js
Last active March 1, 2016 23:06
Design Patterns : Module Pattern
/**
* @fileoverview The base object to generate modules
* @author hwclass
*/
/**
* models/Module.js
* This object is used to generate some instances
* as modules to be attached into the MODULES array.
*/
@hwclass
hwclass / Config.js
Created July 2, 2015 09:00
Design Patterns : Singleton Pattern
/**
* @fileoverview The base object to get configuration
* @author hwclass
*/
/**
* models/Config.js
* This object is used to fetch needed configuration parameters
*/
@hwclass
hwclass / Mediator.js
Created July 2, 2015 09:15
Design Patterns : Mediator Pattern
/**
* @fileoverview The mediator object file
* @author hwclass
*/
/**
* Mediator.js
* This object is used to fetch needed configuration parameters
*/
@hwclass
hwclass / ajax.js
Created July 2, 2015 09:24
Design Patterns : Publish / Subscribe Pattern
/**
* @fileoverview The sample js file that are thought that publishes the coming data from an API endpoint
* @author hwclass
*/
/**
* ajax.js
* This file contains a publish command for productsFetchedEvent
*/
@hwclass
hwclass / Person.js
Created July 2, 2015 09:40
Design Patterns : Mixin Pattern
/**
* @fileoverview The sample js file for Person object
* @author hwclass
*/
/**
* Person.js
* This file contains an object to be a reference for new instances
*/
@hwclass
hwclass / testView.html
Last active August 29, 2015 14:24
Design Patterns : MV* Pattern
<span data-bind="text : testText"></span>