Last active
June 22, 2021 08:30
collection of js code & techniques
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
,---._ | |
.-- -.' \ | |
| | : | |
: ; | | |
: | .--.--. | |
| : :/ / ' | |
: | : /`./ | |
| ; | : ;_ | |
___ l \ \ `. | |
/ /\ J : `----. \ | |
/ ../ `..- ,/ /`--' / | |
\ \ ;'--'. / | |
\ \ ,' `--'---' | |
"---....--' | |
A DEDICATED SPACE TO A SERIES OF JS TECHNIQUES | |
COLLECTED IN THEIR MOST ELEMENTARY FORM. | |
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
//// this is an exemple of autopopulated class structure | |
//// https://jsfiddle.net/nk2mfs0z/15/ | |
class PATHS | |
{ | |
constructor() | |
{ | |
this.gethost(); | |
} | |
sethost(hostname) | |
{ | |
if(!hostname) paths.host = "http://localhost/"; | |
else paths.host = hostname; | |
} | |
gethost() | |
{ | |
return paths.host; | |
} | |
} | |
const paths = {}, pathdata = new PATHS(); | |
pathdata.sethost("http://mysite.com/"); | |
alert(paths.host); | |
let actualhost = pathdata.gethost(); | |
alert(actualhost); |
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
//// this is an exemple of singleton structure | |
//// https://jsfiddle.net/3rjn950m/8/ | |
const person = { | |
name, | |
setName: newName => { | |
this.name = newName; | |
}, | |
getName: () => | |
{ | |
return this.name; | |
} | |
} | |
person.setName("MARIO ROSSI"); | |
alert(person.getName()); |
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
//// exemple of browser check | |
/// https://jsfiddle.net/2eg2yuzy/ | |
function BrowserCheck() | |
{ | |
var N= navigator.appName, ua= navigator.userAgent, tem; | |
var M= ua.match(/(opera|chrome|safari|firefox|msie|trident)/?\s*(.?\d+(.\d+)*)/i); | |
if(M && (tem= ua.match(/version/([.\d]+)/i))!= null) {M[2]=tem[1];} | |
M= M? [M[1], M[2]]: [N, navigator.appVersion,'-?']; | |
return M; | |
} | |
alert(BrowserCheck()) |
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 MYCLASSNAME | |
{ | |
constructor() | |
{ | |
this.myfunctionone(); | |
this.myfunctiontwo(); | |
} | |
myfunctionone() | |
{ | |
this.mydata = String(window.location); | |
} | |
myfunctiontwo() | |
{ | |
this.mydata = String(window.location); | |
} | |
myfree() | |
{ | |
return mydata = String(window.location); | |
} | |
} | |
const myclassname = new MYCLASSNAME(); |
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 arrays = [ ['apple', ['taco', 'fish', 'apple', 'pizza'], 'banana', 'pear', 'fish', 'pancake', 'taco', 'pizza'], ['banana', 'pizza', 'fish', 'apple'] ]; | |
var result = arrays.shift().filter(function(v) { | |
return arrays.every(function(a) { | |
return a.indexOf(v) !== -1; | |
}); | |
}); |
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
//// this is an exemple of cross browser iframe content getter | |
//// https://stackoverflow.com/questions/7570496/getting-the-document-object-of-an-iframe | |
function getIframeContent(f) { | |
if (f.contentWindow) return f.contentWindow; else if (f.window) return f.window; | |
let c = (f.contentDocument) ? f.contentDocument : (f.document) ? f.document : false; | |
return (c && doc.defaultView) ? c.defaultView : (c && c.parentWindow) ? c.parentWindow : undefined; | |
} |
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
//// this is an exemple of recoursive stepper loop | |
let elements = [...myarray], | |
step = 0; | |
( loopbystep = () => { | |
// make step | |
initStep( elements[step], step, otherparams, | |
() => { | |
//up step | |
step++; | |
//start new loop step whit new step | |
if( step < elements.length ) { loopbystep(elements,step); } | |
}); | |
})(array,step,otherparams); | |
// operation for this step | |
function initStep(elements,step,otherparams,back) | |
{ | |
//elements[step] do, if all done: | |
back(); //return to initStep | |
} |
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
//// this is an exemple of recoursive trimmed string | |
function trim(value) | |
{ | |
var temp = value; | |
var obj = /^(\s*)([\W\w])(\b\s$)/; | |
if (obj.test(temp)) { temp = temp.replace(obj, '$2'); } | |
var obj = / +/g; | |
temp = temp.replace(obj, " "); | |
if (temp == " ") { temp = ""; } | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment