Testing TPT
Electron 24/01/2022
- login free
- login premium
- remember password
- not remember password
<!doctype html> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script> | |
//JS to explain | |
//literals var function = + a.b () | |
//methods to explain |
I recently run into a scenario highlighting that await
is not always a drop-in, better replacement for then
. Sometimes with then
it's easier to control the scope of the function that runs after the promise is settled. I have a Redux middleware-inspired example here:
https://codesandbox.io/s/eager-wildflower-1kodv?file=/src/index.js
In example 2, the next call will only happen after the promise resolves.
In example 3, the next will be called immediately.
const haveSameKeys = (objA, objB) => { | |
const keysOfA = Object.keys(objA) | |
const keysOfB = Object.keys(objB) | |
return keysOfA.length === keysOfB.length && | |
keysOfA.every(key => keysOfB.includes(key)) | |
} |
// @ts-check | |
const createRandomInteger = (limit) => Math.floor(Math.random() * limit) | |
const createRandomLetter = () => String.fromCharCode(97 + createRandomInteger(26)); | |
const positionLetter = (element) => { | |
element.style.width = '1vw' | |
element.style.height = '1vw' | |
element.style.lineHeight = '1vw' |
I am always baffled by the complicated graphs people draw to explain the ES3 concept for inheritance. I don't think inheritance is the right word for what is in the language. The more appropriate word would be composition. Prototypal composition, because an object called prototype
is used to bring in that magic. If you think this means JS doesn't have inheritance, don't forget that the goal is not to be able to inherit. What we are trying to achieve is code reuse, small memory footprint and polymorhism (defined here as an ability to mutate object slightly in relation to their generic prototypes).
ES3 in it's attempt to imitate Java (for familiarity purposes) emphasised the role of the class in instances creation. The idea was/is as follows
//1. Functions also serve as classes. There is no separate `class` keyword.
function Animal( sound ) {
if (typeof handleTrackableClickEvent !== "function") { | |
var handleTrackableClickEvent = function(event) { | |
var trackableSelector = '.trackable'; | |
if (event.target) { | |
// msMatches is for IE | |
var matches = event.target.matches || event.target.msMatches; | |
if (matches && matches.call(event.target, trackableSelector)) { | |
var et = event.target; |
const isPrime = number => { | |
let divisor = 2 | |
while (divisor < number) { | |
if(number % divisor === 0) return false | |
divisor += 1 | |
} | |
return true | |
} | |
const findPrime = (timeLimitMS) => { |
// IDEA: start with an object using a symbol as a marker | |
const create = (obj, changeSet) => Object.assign(Object.create(obj || {[Symbol.for('versionstart')]: true}), changeSet); | |
const getPreviousState = obj => { | |
const maybePrev = Object.getPrototypeOf(obj); | |
if (!maybePrev || maybePrev[Symbol.for('versionstart')]) { | |
return null; | |
} | |
return maybePrev; | |
} |
// Given a list with data containing sequential property such as year of birth, age, size | |
// Create a graph containing elements groupped by that property with ids of next nodes | |
// Output example | |
{ | |
'1': {list: [{size: 1}, {size: 1}], previous: undefined, next: '3'}, | |
'3': {list: [{size: 3}], previous: '1', next: '4'}, | |
'4': {list: [{size: 4}], previous: '3', next: undefined}, | |
} |