Skip to content

Instantly share code, notes, and snippets.

View edubskiy's full-sized avatar

Evgeniy Dubskiy edubskiy

View GitHub Profile
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
/**
* Bind context for the given function
*
* @example:
* var Person = {
* name: 'John'
* };
* function walk() {
* console.log(this.name + ' walks');
* }
@edubskiy
edubskiy / fn.include.prototype.js
Created June 22, 2013 19:43
Add inherited properties for object
/**
* Add inherited properties for object
*
* @param {object} properties - inheritable properties
* @param {object} obj - inheritable object
*/
function include(properties, obj) {
var included = properties.included;
for(var name in properties) {
obj.prototype[name] = properties[name];
@edubskiy
edubskiy / fn.extend.static.js
Created June 22, 2013 19:44
Add static properties for object
/**
* Add static properties for object
*
* @param {object} properties - extendable properties
* @param {object} obj - extended object
*/
extend: function(properties, obj) {
var extended = properties.extended;
for(var name in properties) {
obj[name] = properties[name];
@edubskiy
edubskiy / fn.inArray.js
Created June 22, 2013 19:44
Check if elem contains within array
/**
* Check if elem contains within array
*
* @param array
* @param elem checking value
* @returns {int}
*/
inArray: function(array, elem) {
var indexOf = [].indexOf;
if (indexOf) {
@edubskiy
edubskiy / fn.createObject.js
Created June 22, 2013 19:48
Creates new object and sets its prototype with given
/**
* Creates new object and sets its prototype with given
*
* @param o inherited object
* @returns {object}
*/
create: function(o) {
if (Object.create) {
return Object.create(o);
}
@edubskiy
edubskiy / functional.inheritence.js
Created June 22, 2013 19:51
Functional Prototype Inheritance Pattern
/**
* Functional Prototype Inheritance Pattern
* @author E.Dubskiy
* @email e.dubskiy@gmail.com
* @example:
* var Animal = new Class,
* Dog = new Class(Animal);
* Dog.include({
* bark: true
* });
@edubskiy
edubskiy / js.css.minify.makefile
Last active December 18, 2015 20:48
Make file sample
# Original http://wonko.com/post/simple-makefile-to-minify-css-and-js (Thank you by the way)
# Patterns matching CSS files that should be minified. Files with a -min.css
# suffix will be ignored.
CSS_FILES = $(filter-out %-min.css,$(wildcard \
public/css/*.css \
public/css/**/*.css \
))
# Patterns matching JS files that should be minified. Files with a -min.js
# suffix will be ignored.
@edubskiy
edubskiy / namespace.singletone.js
Created June 23, 2013 16:57
Namespaced singletone shortcut
// Create global namespace
App = {};
// Attach your singletone method as shortcut inside
App.Event = (function() {
var instance;
return function() {
if (!instance) {
instance = new Event();
}