kindring 4 years ago
parent
commit
02e4c21515

+ 3 - 0
express/小技巧.md

@@ -0,0 +1,3 @@
+# 如何处理请求参数
+1. 封装方法,根据不同的请求类型来获取不同的参数 
+> 利用 

+ 53 - 0
js/任务执行.md

@@ -0,0 +1,53 @@
+# js中的任务类型
+    1. 宏任务
+       1. settimeout
+       2. setInterval
+       3. MessageChannel
+       4. I/O,事件队列
+       5. setImmediate
+       6. script
+    2. 微任务
+       1. requestAnimationFrame
+       2. MutationObserver
+       3. Promise.[then/catch/finally]
+       4. process.nexTick
+       5. queueMicrotask
+# js中异步任务执行规则
+    先顺序执行下去,有遇到异步任务将其放置一边,然后继续执行下面的任务,执行完同步任务后再去看异步任务中的微任务是否有执行完了的,如果有则执行,执行完后则去执行宏任务,以此来完成一次循环
+# js中promise和setTimeout谁先执行
+ 1. 在js中的promise视为微任务,settimeout为宏任务 根据执行规则微任务先执行,所以promise会先执行
+ 2. 示例代码
+    ```
+        console.log(1); //1
+        new Promise((resolve, reject) => {
+            console.log(2); //2
+            resolve();
+        }).then(() => {
+            console.log(3) //4
+        });
+        setTimeout(() => {
+            console.log(4) //6
+        });
+        setTimeout(() => {
+            console.log(5) //7
+        });
+        new Promise((resolve, reject) => {
+            console.log(6); //3
+            resolve();
+        }).then(() => {
+            console.log(7); //5
+        });
+        new Promise((resolve, reject) => {
+            console.log(8);
+            setTimeout(() => {
+                console.log(9)
+                resolve();
+            });
+        }).then(() => {
+            console.log(10);
+        });
+        // 1 2 6 8 3 7 4 5 9 10
+    ``` 
+
+
+

+ 8 - 3
vuex相关.md

@@ -66,6 +66,11 @@
             }
         })
     ```
-  
-## 4. 这到底是个啥?
-## 6. 我又悟了
+  ### 随缘记录的vue小技巧
+    1. vue中的ref可以进行重名,重名后不会报错,只需要使用下标进行访问
+        1. 正常情况
+        > 直接使用 this.$refs.name 即可访问 
+        2. 重名情况下 
+        > this.$refs.names[0] 可以访问
+## 4. 先留着这个板块
+## 6. 我悟了

+ 6 - 0
坑/闹钟方案.md

@@ -0,0 +1,6 @@
+# 功能需求
+## 指定闹钟功能
+1. 定时闹钟
+   1. 每天指定时间
+   2. 每周指定的时间
+2. 延长闹钟时间

+ 16 - 0
奇思妙想/app.js

@@ -0,0 +1,16 @@
+function getIPAddress() {
+    var interfaces = require('os').networkInterfaces();
+    for (var devName in interfaces) {
+        var iface = interfaces[devName];
+        for (var i = 0; i < iface.length; i++) {
+            var alias = iface[i];
+            if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
+                return alias.address;
+            }
+        }
+    }
+}
+
+const LOCAL_IP = getIPAddress();
+const port = 3000;
+console.log(`server to http://${LOCAL_IP}:${port}`);

+ 65 - 0
奇思妙想/index.js

@@ -0,0 +1,65 @@
+let d = arguments[1]('./t.js');
+
+console.log(d);
+
+function abc() {
+    let obj = {
+        name: '15'
+    }
+    obj.__proto__ = {
+        bb(str) {
+            console.log(str);
+        },
+    };
+    obj.__proto__.constructor = function() {
+
+    }
+    return obj
+}
+
+function fn(that, cb) {
+    return function() {
+        cb.call(that)
+    }
+}
+abc.prototype.sayHello = function() {
+    setTimeout(new fn(this, function() {
+        console.log(`你好,我叫${this.name}`);
+    }), 15);
+}
+let b = new abc();
+console.log(b.name); //{ name: '15' }
+console.log(typeof b); //obj
+console.log(abc.sayHello);
+b.bb('-------'); //-------
+console.log(b.sayHello); //undefined
+
+
+function abc3() {
+    this.name = 'n'
+}
+
+abc3.prototype.sayHello = function() {
+    console.log(`你好,我叫${this.name}`);
+}
+
+// abc3.sayHello();
+
+
+//error
+// let c = new(() => {
+//     let obj = {
+//         name: '15'
+//     }
+//     obj.__proto__ = this;
+//     return obj
+// })();
+// console.log(c);
+
+//ok
+
+let a = () => {
+    console.log(arguments);
+};
+// console.log(arguments);
+arguments[2]

+ 100 - 0
奇思妙想/t.js

@@ -0,0 +1,100 @@
+// arguments[2].exports.c = { a: 1 }
+// let b = [].slice.call(arguments)
+
+function test2() {
+    console.debug(this)
+}
+
+// test2.call({ name: '2' });
+// test2.call(Object);
+// test2.call(null);
+// test2.call(undefined);
+
+var d = 0;
+for (var i = 0, j = 0; i < 10, j < 6; i++, j++) {
+    // console.log(i);
+    d = i + j;
+}
+// console.log(d);
+
+// const { b: a } = { a: 123 } //b123
+
+
+
+
+function Obj(obj) {
+    for (const key in obj) {
+        this[key] = typeof obj[key] == 'object' ? new Obj(obj[key]) : obj[key];
+    }
+}
+let a = { name: 123, age: 999 };
+let f = { t: 1, a: a };
+// a.f = f;
+f.d = new Date();
+let c = new Obj(f);
+console.log(f);
+console.log(c)
+f.t = 'test';
+console.log(f);
+console.log(c)
+a.name = '张3';
+console.log(f);
+console.log(c);
+// console.log(c.t);
+
+console.log(1); //1
+new Promise((resolve, reject) => {
+    console.log(2); //2
+    resolve();
+}).then(() => {
+    console.log(3) //4
+});
+setTimeout(() => {
+    console.log(4) //6
+});
+setTimeout(() => {
+    console.log(5) //7
+});
+new Promise((resolve, reject) => {
+    console.log(6); //3
+    resolve();
+}).then(() => {
+    console.log(7); //5
+});
+new Promise((resolve, reject) => {
+    console.log(8);
+    setTimeout(() => {
+        console.log(9)
+        resolve();
+    });
+}).then(() => {
+    console.log(10);
+});
+// 1 2 6 8 3 7 4 5 9 10
+
+function pr(s) {
+    console.log(11);
+    console.log(s);
+}
+
+function print2(s) {
+    console.log(22);
+    pr(s);
+}
+
+//11 1
+//22 11 2
+// 22 11 6
+// 11 7
+// 22 11 3
+// 22 11 8
+// 22 11 4
+// 22 11 5
+
+new Promise((resolve, reject) => {
+    resolve.call(new Promise((r) => {
+        r('hhh')
+    }));
+}).then((val) => {
+    console.log(val);
+})

+ 30 - 0
简单题目/index.js

@@ -0,0 +1,30 @@
+// 
+function exit(maxLen, baseArr, newNumber) {
+    // 创建一开始的随机数
+    newNumber = newNumber === 0 ? newNumber : newNumber || Math.floor(Math.random() * 31 + 2);
+    //创建一开始的数组
+    baseArr = baseArr || [];
+    let isExit = false;
+    for (var i in baseArr) {
+        if (baseArr[i] === newNumber) {
+            isExit = true;
+            break;
+        }
+    }
+    //存在的话则递归获取不存在的数;
+    if (isExit) {
+        //创建新的数据
+        newNumber = exit(maxLen, baseArr);
+    } else {
+        //不存在于数组中,添加到数组内
+        baseArr.push(newNumber);
+        if (baseArr.length === maxLen) {
+            return baseArr;
+        } else {
+            baseArr = exit(maxLen, baseArr)
+        }
+    }
+    return baseArr;
+}
+console.log(exit(5));
+console.log(exit(5));

+ 7 - 0
简单题目/去除空格.js

@@ -0,0 +1,7 @@
+var trim = function(str) {
+    return str.replace(/\s*/g, "");
+}
+str.replace(/\s*/g, ""); //去除字符串内所有的空格
+str.replace(/^\s*|\s*$/g, ""); //去除字符串内两头的空格
+str.replace(/^\s*/, ""); //去除字符串内左侧的空格
+str.replace(/(\s*$)/g, ""); //去除字符串内右侧的空格

+ 2 - 0
简单题目/题目.md

@@ -0,0 +1,2 @@
+# 用递归算法实现,数组长度为5且元素的随机数在2-32间不重复的值
+数组长度为5 随机数2-32