我的工作学习总结

天下5912

GET IN TOUCH

你好!

No Title

Prototype Chain

Property Shadowing

How to implement inheritance

Object.create()

New

Event Loop

Each message is processed completely before any other message is processed.

Never blocking

Macrotask queue

From the browser’s perspective, a macrotask represents one discrete, self-contained unit of work.

mouse events
keyboard events
network events
html parsing

microtask queue

Microtasks, on the other hand, are smaller tasks that update the application state and should be executed before the browser continues with other assignments such as re-rendering the UI.

dom mutations
promises

通过场景了解概念

debounce

function debounce(callback, wait) {
let timeout;
return (…args) => {
clearTimeout(timeout);
timeout = setTimeout(() => callback.apply(this, args), wait);
};
}

throttle

function throttle(func, limit) {
let inThrottle;
return (…args) => {
if (!inThrottle) {
func.apply(this, args);
inThrottle = true;
setTimeout(() => (inThrottle = false), limit);
}
};
}

Promise.all

function PromiseAll(values) {
return values.reduce((accumulator, value) => {
return accumulator.then((results) => {
return Promise.resolve(value).then((result) => {
return […results, result];
});
});
}, Promise.resolve([]));
}

currying

function curry(f) {
return function (a) {
return function (b) {
return f(a, b);
};
};
}

function sum(a, b) {
return a + b;
}

let curriedSum = curry(sum);

console.log(curriedSum(1)(2));