获得徽章 1
- 4 月 11 日 day15
今日学习 学习了 antdesign 源码的调试,还了解了 vscode 调试代码的方法和一些技巧,并且了解了通过 sourcemap 调试 antdesign 的 tsx源代码赞过评论1 - 4月10日 day14
今日学习学习 fabricjs 的基本使用,了解了它的一些常用的 api 及应用场景。并进行实战完成了一个简单的图片编辑器。评论点赞 - #每日一题# 快排
var example=[1,4,3,8,9,6,2]
function quickSort(arr){
if(arr.length<=1){
return arr;
}
var left=[],right=[],current=arr.splice(0,1);
for(let i=0;i<arr.length;i++){
if(arr[i]<current){
left.push(arr[i])
}else{
right.push(arr[i])
}
}
return quickSort(left).concat(current,quickSort(right));
}
console.log(quickSort(example));
function quickSort(arr,l,r){
if(l < r){
var i = l, j = r, x = arr[i];
while(i<j){
while(i<j && arr[j]>x)
j--;
if(i<j)
arr[i++] = arr[j];
while(i<j && arr[i]<x)
i++;
if(i<j)
arr[j--] = arr[i];
}
arr[i] = x;
quickSort(arr, l, i-1);
quickSort(arr, i+1, r);
}
}
展开评论点赞 - #每日一题# 函数map方法
Array.prototype.myMap = function (callback, thisArg) {
let length = this.length
let res = []
if (!Array.isArray(this)) throw new TypeError('this is not an array')
if (typeof callback !== 'function') throw new TypeError(callback + 'is not a function')
if (length === 0) {
return res
}
for (let i = 0; i < length; i++) {
res[i] = callback.call(thisArg, this[i], i, this)
}
return res
}
展开评论点赞 - #每日一题# 发布订阅模式
class EventEmitter {
constructor() {
this.cache = {}
}
on(name, fn) {
if (this.cache[name]) {
this.cache[name].push(fn)
} else {
this.cache[name] = [fn]
}
}
off(name, fn) {
const tasks = this.cache[name]
if (tasks) {
const index = tasks.findIndex((f) => f === fn || f.callback === fn)
if (index >= 0) {
tasks.splice(index, 1)
}
}
}
emit(name, once = false) {
if (this.cache[name]) {
// 创建副本,如果回调函数内继续注册相同事件,会造成死循环
const tasks = this.cache[name].slice()
for (let fn of tasks) {
fn();
}
if (once) {
delete this.cache[name]
}
}
}
}
展开评论点赞 - 4月6日 day10
今日学习 知道了一些以前未曾了解过的css属性,比如:invalid辅助表单校验,:focus-within子元素状态影响父元素。评论点赞