lkdghzh / blog Goto Github PK
View Code? Open in Web Editor NEWDocs are available at
Home Page: https://unarjs.org
Docs are available at
Home Page: https://unarjs.org
// dynamic program way
// https://blog.csdn.net/a553181867/article/details/89008264
/**
* @param {string} word1
* @param {string} word2
* @return {number}
*/
var minDistanceTest = function (word1, word2) {
console.log(word1, word2);
const distanceTable = Array.from({ length: word1.length + 1 }, (_, i) => {
const fisrtColumn = Array.from({ length: word2.length + 1 }, (_, j) => j)
const column = new Array(word2.length + 1).fill(i, 0, 1).fill(undefined, 1);
return i === 0 ? fisrtColumn : column
});
for (var i = 1; i <= word1.length; i++) {
for (var j = 1; j <= word2.length; j++) {
// dp
var flag = 1;
if (word1.charAt(i - 1) === word2.charAt(j - 1)) {
flag = 0
}
const left = distanceTable[i - 1][j] + 1;
const top = distanceTable[i][j - 1] + 1;
const leftTop = distanceTable[i - 1][j - 1] + flag;
console.log(`${i},${j}`, Math.min(left, Math.min(top, leftTop)))
distanceTable[i][j] = Math.min(left, Math.min(top, leftTop))
}
}
console.log('distanceTable', distanceTable)
console.log('distanceTable[i][j]', distanceTable[word1.length][word2.length])
return distanceTable[word1.length][word2.length]
};
minDistanceTest('horse', 'ros')
const o = {
fn: () => {
console.log(this)
},
fn1() {
console.log(this)
},
fn2() {
const fn2a = () => {
console.log(this)
}
return fn2a()
}
}
o.fn()
o.fn1()
o.fn2()
var f = o.fn2;
f()
var o2 = { f: o.fn2 }
o2.f()
// https://juejin.cn/post/7035257186565488670
// https://www.bilibili.com/video/BV1qD4y1G7YK/?spm_id_from=333.788&vd_source=6295663755b5924d0280f874eacbe51d
// 17min
将Object对象的一些明显属于语言内部的方法(比如Object.defineProperty),放到Reflect对象上。现阶段,某些方法同时在Object和Reflect对象上部署,未来的新方法将只部署在Reflect对象上。也就是说,从Reflect对象上可以拿到语言内部的方法
var o1 = {
x: 1,
get a() {
return this.x
}
}
console.log(Reflect.getOwnPropertyDescriptor(o1, 'a'))
/*
{
"enumerable": true,
"configurable": true,
get: ƒ a(),
set: undefined
}
*/
var _get = Reflect.getOwnPropertyDescriptor(o1, 'a').get;
var o2={
x:2
}
_get.call(o2) //2
redux中性能优化中有reselect库。采取了备忘录(memo)设计模式
class A {
a = 1;
constructor({ a }) {
this.a = a
};
f = () => { };
fn() {
console.log(1)
}
}
A.prototype.fn()
class A { }
class B extends A {
constructor() { }
}
new B()
// Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
class A { }
class B extends A {
constructor() {
super()
}
}
new B()
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Classes/constructor
// 一条记忆实体(内容)
// 一条备忘
// 仅仅描述一条实体的类。【用value通用,各种数据都能备忘]
class Memento {
constructor(value) {
this.value = value;
}
}
// 多条备忘的集合
// 提供([仅从顶部新增、删除])添加备忘 撤销备忘 ,无删除
class MementosStorage {
constructor(memento) {
// TODO Memento 类型校验
this.value = [memento]
}
get length() {
return this.value.length
}
// do
add(memento) {
return this.value.push(memento)
}
// --> undo
remove(memento) {
return this.value.pop(memento)
}
}
class MementosManager {
constructor(memento) {
this.storage = this.value = new MementosStorage(memento)
}
addMemento(memento) {
return this.storage.add(memento);
}
undo() {
return this.storage.remove();
}
getMemento(index = this.storage.length - 1) {
return this.storage.value[index]
}
motify(index = this.storage.length - 1, memento) {
this.storage.value[index] = memento
}
}
const li = {
name: "li",
phone: 15120065082
}
const zhang={
name: "zhang",
phone: 1
}
const wang={
name: "wang",
phone: 2
}
const zhao ={
name: "zhao",
phone: 3
}
const manager = new MementosManager(li);
var item = manager.getMemento()
console.log('item init', item) // {name: "li", phone: 15120065082}
manager.addMemento(zhang)
var item = manager.getMemento()
console.log('item after add', item) // {name: "zhang", phone: 1}
manager.addMemento(wang)
var item = manager.getMemento()
console.log('item after add', item) // {name: "wang",phone: 2}
manager.addMemento(zhao)
var item = manager.getMemento()
console.log('item after add', item) // {name: "zhao", phone: 3}
manager.undo()
var item = manager.getMemento()
console.log('item after undo',item); // {name: "wang", phone: 2}
manager.undo()
var item = manager.getMemento()
console.log('item after undo',item); // {name: "zhang", phone: 1}
manager.undo()
var item = manager.getMemento()
console.log('item after undo',item); // {name: "li", phone: 15120065082}
char | wchar_t | string | wstring | |
---|---|---|---|---|
char | ||||
wchar_t | 1 | 1 | ||
string | 1 | |||
wstring | 1 | 1 |
运用在函数中,中文(边际效应,附作用),除了函数本身,还有一些附加左右
例如:
const express =require('../lib/express');
const app=express()
app.get('/',function(req,res,next){
console.log(1)
next()
},function(req,res,next){
console.log(2)
next()
},function(req,res){
res.end('end')
})
app.listen(3000)
/**
*
* app.use() //中间件的使用
* app.get() //多个路由层级中间件和回调
* app.route() //restFul
* express.Router() //二级路由
*/
1.启动阶段(框架根据手写app router midsware初始化并启动)
2.请求阶段(get post put delete )require('http').METHODS
method
path
handler
express是一个函数(一个闭包,返回一个函数) app {} Router 是一个函数(一个闭包,返回一个函数,可以new ,可以router)stack Route (class)几个path new几个route stack
Router method
Route use
route
param
handle ...
app express返回的函数 Router(闭包的好处之一,匿名函数返回的函数) Route Layer
app.method(path,handler)
- app.lazyrouter() - new Router()得到router实例(是一个函数)
- router.route(path) - new Route(path)得到route实例
- router.route = route实例
- route.method
- return app
app.use
app.route
app.param
const start1 = Date.now()
function debounce(fn, delay = 5000) {
let timer = null;
// 闭包
return function () {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
timer = null
fn()
}, delay)
}
}
const f = () => { console.log('执行了当前函数', Date.now() - start1) }
const df = debounce(f, 5000)
//模拟每次点击
const clk = _ => new Promise((resolve) => {
setTimeout(() => {
df()
console.log('clk')
resolve()
}, 1000)
});
// 每次点击间隔1000ms,对应的闭包还没放到宏队列
// 在1000ms内,下次点击会立刻清掉上次点击的定时器,四次点击造成前三次都被清除了
// 直到第四次执行,在
const start = Date.now()
console.log('开始')
//第一次点击
console.log('clk')
df();
// 开始
// clk
// 执行了当前函数 5004
// (async function () {
// console.log('第一次点击耗时', Date.now() - start);
// //第一次点击
// await clk();
// console.log('第二次点击耗时', Date.now() - start)
// //第二次点击
// await clk();
// console.log('第三次点击耗时', Date.now() - start)
// //第四次点击
// await clk();
// console.log('第四次点击耗时', Date.now() - start)
// })()
// 开始
// clk
// 第一次点击耗时 4
// clk
// 第二次点击耗时 1008
// clk
// 第三次点击耗时 2010
// clk
// 第四次点击耗时 3012
// 执行了当前函数 8011
// 优点:防抖可以防止多次抖动执行一次
// 弊端:最后一次延迟delay执行
逻辑复用的问题
HOC
https://juejin.cn/post/6844904050236850184
render
https://blog.csdn.net/qianyu6200430/article/details/109881828?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
顶层写hooks
https://www.yuque.com/sunluyong/interview/tf7wc3
源码位置
require.ensure
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.