Skip to content

Instantly share code, notes, and snippets.

View ppraksa's full-sized avatar
👋

Pawel ppraksa

👋
View GitHub Profile
@ppraksa
ppraksa / async.js
Last active March 22, 2017 12:48
thenable
var ASYNC = {
then: function then(o) {
typeof o === 'function' ? o() : false;
return {
then : this.then,
defer : this.defer
}
},
defer: function then(o,t) {
return new Promise(function(res,rej) {
@ppraksa
ppraksa / gist:502f36fe366b6683ca8f9613e2084dae
Last active March 22, 2017 11:24
Combaine promise with generator
//Combaine promise with generator
function *getUrl(url) {
try {
var response = yield getReq(url).then(function(fb) {
console.log('feedback!!!');
console.log(fb);
return fb;
},
function(e) {
@ppraksa
ppraksa / isN.js
Last active March 23, 2017 12:34
extend to the number
// is Number this = global scope (window)
if(typeof this.isN != "function" && (this.constructor.name).toLowerCase() === "window") {
this.isN = function (...args) {
let newArgs = [];
newArgs = args.map((e) => {
return !isNaN(e)
});
return newArgs;
};
}
@ppraksa
ppraksa / classdoesnothoist.js
Last active March 22, 2017 13:38
"to hoist or not to hoist"
var cat = new Cat() // it's ok !
cat.sayHello(); // then we call sayHello without any problem!
function Cat() {
this.sayHello = function() {
console.log('hello Im a cat');
}
}
@ppraksa
ppraksa / suprsie.js
Created March 23, 2017 12:10
'this' scope on arrow fn
var a = 2;
var Obj = {
a: 4,
test: () => {
console.log(a);
console.log(this.a);
},
test2: function({a = 6}) {
console.log(a);
@ppraksa
ppraksa / symboliterator.js
Created March 24, 2017 13:28
Symbol.iterator
let a = [1,2,3,4,5,6,7,8,9,0],
tmp = 0,
it = a[Symbol.iterator]();
do {
tmp = it.next();
if(tmp.value != undefined) {
console.log(`Value is: ${tmp.value}`);
}
} while(!tmp.done)
@ppraksa
ppraksa / argumentsareint.js
Created March 24, 2017 15:44
Simple test wit cb
function test(...args) {
try {
var cb = args.pop();
(cb.constructor.name === 'Function') ? null : new Error('isnt fn');
let a = args,
tmp = 0,
it = a[Symbol.iterator]();
do {
tmp = it.next();
if(tmp.value != undefined) {
@ppraksa
ppraksa / distro.js
Created March 24, 2017 15:47
Example of entries - gulp disto
/**
* distro.
* @module distro.
* @version 1.0.0
*
* @author ppraksa
* @copyright (c) 2017 ppraksa.
*/
const distro = {},
@ppraksa
ppraksa / mixin.js
Created March 31, 2017 09:43
Typical mixin in js
Object.prototype.mixin = function(obj) {
if(typeof obj === 'object') {
for(let i in obj) {
String(i) in this ? `${i} - property exist` : this[i] = obj[i];
}
}
}
var Vehicle = { works: true, tank: 100, hasWheels: true }
@ppraksa
ppraksa / parasite.js
Last active March 31, 2017 10:02
Like a parasite
Object.prototype.parasiteCopy = function(obj, args) {
if(typeof obj.constructor === 'function') {
obj.apply(this, args);
}
}
var Plant = function(colour,roots) {
this.colour = colour;
this.roots = roots
}