Skip to content

Instantly share code, notes, and snippets.

View rochnyak-d-i's full-sized avatar

rdi rochnyak-d-i

View GitHub Profile
@rochnyak-d-i
rochnyak-d-i / carry.js
Last active August 29, 2015 14:08
JS каррирование
function carry(fn) {
var
slice = Array.prototype.slice
, soredArgs = slice.call(arguments, 1)
;
return function() {
var
newArgs = slice.call(arguments)
, args = soredArgs.concat(newArgs)
@rochnyak-d-i
rochnyak-d-i / namespaces.js
Last active August 29, 2015 14:08
JS Пространства имен
function namespace(ns_string) {
var
parts = ns_string.split('.')
, parent = MYAPP
, i
, length
;
// отбросить начальный префикс – имя глобального объекта
if (parts[0] === 'MYAPP') {
parts = parts.slice(1);
@rochnyak-d-i
rochnyak-d-i / dependencies.js
Last active August 29, 2015 14:08
JS Зависимости
function Sandbox() {
// преобразовать аргументы в массив
var
args = Array.prototype.slice.call(arguments)
// последний аргумент ­ функция обратного вызова
, callback = args.pop()
// имена модулей могут передаваться в форме массива
// или в виде отдельных параметров
, modules = (args[0] && typeof args[0] === 'string') ? args : args[0]
, i
@rochnyak-d-i
rochnyak-d-i / constant.js
Created October 26, 2014 11:51
JS Константы
var constant = (function() {
var
constants = {}
, ownProp = Object.prototype.hasOwnProperty
, allowed = {
string: 1
, number: 1
, boolean: 1
}
, prefix = (Math.random() + '_').slice(2)
@rochnyak-d-i
rochnyak-d-i / class.js
Last active August 29, 2015 14:08
JS класс
var klass = function(Parent, props) {
var Child, i;
//новый конструктор
Child = function() {
if(Child.uber && Child.uber.hasOwnProperty('__constructor')) {
Child.uber.__constructor.apply(this, arguments);
}
if(Child.prototype.hasOwnProperty('__constructor')) {
@rochnyak-d-i
rochnyak-d-i / extend.js
Last active August 29, 2015 14:08
JS расширение
function extend(parent, child) {
var i;
child = child || {};
for(i in parent) {
if(parent.hasOwnProperty(i)) {
child[i] = parent[i];
}
}
return child;
@rochnyak-d-i
rochnyak-d-i / abstract_factory.js
Last active August 29, 2015 14:08
JS шаблон абстрактная фабрика
function BluePopup () {
//создание всплывающего окна
}
BluePopup.prototype.attach = function (elemens) {
//присоединение других ui-элементов к окну
}
BluePopupFactory.register('popup', BluePopup);
@rochnyak-d-i
rochnyak-d-i / bind.js
Last active August 29, 2015 14:08
JS Связывание
if (typeof Function.prototype.bind === 'undefined') {
Function.prototype.bind = function (thisArg) {
var
fn = this
, slice = Array.prototype.slice
, args = slice.call(arguments, 1)
;
return function () {
return fn.apply(thisArg, args.concat(slice.call(arguments)));
@rochnyak-d-i
rochnyak-d-i / extendDeep.js
Created October 28, 2014 04:51
JS рекурсивное расширение
function extendDeep(parent, child) {
var
toStr = Object.prototype.toString
, astr = '[object Array]'
, i
;
child = child || {};
for(i in parent) {
@rochnyak-d-i
rochnyak-d-i / object_create.js
Created October 28, 2014 04:53
JS создание объекта
Object.create || Object.create = function object(o) {
function F(){}
F.prototype = o;
return new F();
}