Skip to content

Instantly share code, notes, and snippets.

View projektorius96's full-sized avatar
🐢
Turtles do code

LG projektorius96

🐢
Turtles do code
View GitHub Profile
// callback executer
let y = function(doCallBack) {
console.log("This is dependent function expression which will inquire callback");
doCallBack(); /* doCallBack parameter defined and executed itself inside dependant function expression ensure callback as argument will be inquired and returned subsequently */
};
// calback ifself
let x = function() {
console.log('This is the body of independent function expression, which says: "I am callback called as argument"');
};
@projektorius96
projektorius96 / Object_prototype_instance_example1
Last active July 26, 2019 21:27
Object_prototype_constructor_example1
// Constructor function for myObj
function myObj(firstValue, secondValue, thirdValue, undefined) {
this.firstKey = firstValue; // disabled due null
this.secondKey = secondValue; // second parameter is enabled; all the rest are disabled in console output;
this.thirdKey = thirdValue; // disabled due null;
this.nKey = undefined; // disabled due undefined;
}
// Create a myObject; Object Instance name ::after keyword "new" must match name of the function constructor name defined above!
var userInput = new myObj("Index1userA", "JavaScript", "Index3userC", "Index4userD"); /* Basically, what User1 inputs inside parantheses
@projektorius96
projektorius96 / firstChild
Last active January 2, 2019 12:21
firstChild vs. firstElementChild
<!DOCTYPE html>
<html>
<body>
<p><u>Example list</u>:</p>
<ul id="myList"><!-- Delete this firstChild text-comment node in order to get Absence of whitespace as HTML element presented in yellow color. Otherwise Absence of whitespace as HTML element is described as undefined and Presence of whitespace as HTML element presented in red color p.s avoid ENTER in this example i.e manipulate only with comment area --><li id="demo1">Absence of whitespace</li><li id="demo2">Presence of whitespace</li></ul>
<p><b>Click the button to get the HTML content of the list's first child node:</b><br> a) result in yellow color or "Absence of whitespace" is undefined + case b)<br> b) result in red color as "Presence of whitespace"</p>
<button onclick="myFunction()">Try it</button>
@projektorius96
projektorius96 / eListener-with-eObjectParameter.js
Last active January 17, 2019 07:17
eListener-with-parameter for [object Window] (console.log example)
function eHandler(eventObjectParameterGoes1st) {
/* var objTarget = eventObjectParameterGoes1st.target;
objTarget.style.backgroundColor = "yellow"; */
eventObjectParameterGoes1st.target.style.backgroundColor = "yellow"; // _if using shortcut
}
var variableWin = this; // keyword THIS represent [object Window] in JS
variableWin.addEventListener('mouseover', function (eventObjectParameterGoes1st) {
eHandler (eventObjectParameterGoes1st); }, false);
@projektorius96
projektorius96 / eListener-with-multiParameters.js
Created January 17, 2019 07:12
eListener-with-parameters for [object Window] (console.log example)
function eHandler(e, addCustomColor) {
var objTarget = e.target;
objTarget.style.backgroundColor = addCustomColor;}
var variableWin = this; // keyword THIS represent [object Window] in JS
variableWin.addEventListener('mouseover', function (e) {
eHandler (e, 'yellow'); }, false);
var someVariable = new Object;
// same alternative written below;
var someVariable = {}; // {object Object syntax}
var i = 0; // define zero number to start loop at
while (i < 6) { // start at zero
if (i === 3) { // when loop reaches number 3...
break; //... break the loop and return 3 as terminal number of the loop
}
i = i + 1; // alter variable i to 3. Start at 0, when i = 1, when i = 2, when i = 3 BREAK!
}
console.log(i); // console variable i
// expected output: 3
@projektorius96
projektorius96 / arguments as items of array
Last active November 21, 2019 21:32
arg1, "" where "" helps out to avoid undefined attached to in console output
var paramArr = [" love you", " when you smile"];
[arg1, arg2] = paramArr;
// [modified] const [arg1, arg2] = paramArr;
function iLoveYou (arg1, arg2) {
return arg1 + arg2;
}
iLoveYou(arg1, "");
@projektorius96
projektorius96 / Decrement--
Created April 21, 2019 15:58
for loop decrement
for (var counter = 10; counter > 0; counter--) {
console.log(counter)
}
var NumbersToOne = {
[Symbol.iterator]: ()=> {
var i = 10;
return {
prev: ()=> {
if (i > 0) {return { value: i--, done: false };}
else if (i == 0) {{return { value: i--, done: true };}
}
}
};