This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(o, /^[0-9]+$/, { | |
get : function() { }, | |
set : function() { }, | |
enumerate : function() { }, | |
writable : false, | |
configurable : false, | |
enumerable : false | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor(...elements) { | |
// Initializing the queue with given arguments | |
this.elements = [...elements]; | |
} | |
// Proxying the push/shift methods | |
push(...args) { | |
return this.elements.push(...args); | |
} | |
shift(...args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Queue { | |
constructor(...elements) { | |
// Initializing the queue with given arguments | |
this.elements = [...elements]; | |
} | |
// Proxying the push/shift methods | |
push(...args) { | |
return this.elements.push(...args); | |
} | |
shift(...args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
constructor(...elements) { | |
// Initializing the stack with given arguments | |
this.elements = [...elements]; | |
} | |
// Proxying the push/shift methods | |
push(...args) { | |
return this.elements.push(...args); | |
} | |
pop(...args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Singleton pattern | |
var MySingleton=(function() { | |
// creating a variable to contain the instance | |
var instance=null; | |
// here goes private stuff | |
var _myPrivateVar=1; | |
var _myPrivateFunction=function(){ | |
console.log('In private function.'); | |
}; | |
// creating singleton constructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inherit JavaScript Singleton | |
function ParentConstructor() {} | |
ParentConstructor.prototype.publicProperty1=1; | |
var InheritSingleton=(function(parentConstructor) { | |
// creating a variable to contain the instance | |
var instance=null; | |
// creating singleton constructor | |
function Constructor() { | |
// assigning instance to our variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------- Database section | |
// current version | |
var __versions__ = ['1.0.1','1.0.2','1.0.3']; | |
var __version__ = localStorage.getItem('db:version') | |
||__versions__[__versions__.length-1]; | |
function migrate_1_0_1() { | |
console.log('going into migrate_1_0_1'); | |
} | |
function migrate_1_0_2() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Math.random=(function(rand) { | |
var salt=0; | |
document.addEventListener('mousemove',function(event) { | |
salt=event.pageX*event.pageY; | |
}); | |
return function() { return (rand()+(1/(1+salt)))%1; }; | |
})(Math.random); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise=(function() { | |
var AWAIT=0, SUCCESS=1, FAIL=-1; | |
function Promise(logic) { | |
var promise=this; | |
promise.solved=AWAIT; | |
var success=function (value) { | |
if(AWAIT!==promise.solved) | |
return; | |
promise.solved=SUCCESS; | |
promise.value=value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence | |
(function(win, doc){ | |
if(win.addEventListener)return; //No need to polyfill | |
function docHijack(p){ doc[p]=(function(old){ return function(v){return addListen(old(v))}; })(doc[p]);} | |
function addEvent(on, fn, self){ | |
return (self = this).attachEvent('on' + on, function(e){ | |
var e = e || win.event; | |
e.preventDefault = e.preventDefault || function(){e.returnValue = false} | |
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true} |