- 博客(16)
- 收藏
- 关注
原创 JS雷区:手写bind函数的相关问题
手写一个bind函数// 模拟 bindFunction.prototype.bind1 = function () { // 将参数拆解为数组 const args = Array.prototype.slice.call(arguments) // 获取 this(数组第一项) const t = args.shift() // fn1.bind(...) 中的 fn1 const self = this // 返回一个函数 re
2021-07-18 12:53:52 112
原创 JS雷区:函数作为返回值的调用
function fn1() { return function () { console.log("函数作为返回值"); }}fn1()();//调用function test() { return function () { console.log('函数作为返回值'); };}var res = test();console.log(res);res();...
2021-07-18 12:40:04 180
原创 js雷区:关于在声明函数末尾加括号的问题
(function (a) { console.log(a);})('b');//就相当于下面这种写法function c(a) { console.log(a);}c('b');//同样也可以这么写(function c(a) { console.log(a);})('b');// 三者都输出b
2021-07-18 10:12:59 251
原创 JS雷区:没法直接声明二维数组的解决方法
JavaScript似乎没法直接声明二维数组只能先声明一维再声明第二维如下:var a = new Array(4);for (let i = 0; i < a.length; i++) { a[i] = new Array(4);}for (let i = 0; i < 4; i++) { for (let j = 0; j < 4; j++) { a[i][j] = i * j; }}console.log(a);...
2021-07-16 17:13:33 82
原创 JS雷区:Set.has()对数组进行判断的问题
var arr = [[1, 2], [3, 4], [5, 6]];var set = new Set();arr.forEach(v => { set.add(v);})console.log(set);var tmp = [1, 2];console.log(set.has(tmp));//false这是因为,对于数组而言,内存地址指向的数组是不同的,必须深拷贝否则无法判定。...
2021-07-05 15:25:53 2904 1
原创 JS雷区:关于this指向的问题
var name = "window";var person = { name: "wenwen"};function sayName() { console.log(this.name);}sayName();//undefinedsayName.apply(person);//wenwensayName.apply();//undefined这里注意是原生js的编译结果如果在浏览器中执行jssayName();sayName.apply();应该返回的都是win
2021-07-02 11:53:42 44
原创 JS雷区:关于函数返回值简写
(a, b) => a - b//相当于return了a-b,相当于:(a, b) => {return a - b;}
2021-06-25 23:53:07 557
原创 JavaScript雷区:关于has(),get(),hasOwnProperty()
const hash = new Map([["rosen",1],[2,2]]);console.log(hash.has("rosen"));//trueconsole.log(hash.has(1));//falseconsole.log(hash.get("rosen"));//1console.log(hash.hasOwnProperty("rosen"));//false
2021-06-22 22:58:13 612 1
原创 JavaScript雷区:使用[]引用对象必须加双引号
var json = { a: { b: { c: 1, g: 22 }, e: { f: 1 } }, d: [1, 2],};var need = json["a"];console.log(need);// var obj = {// 'name': 'tom',// 'age': 23// };// var
2021-06-21 23:44:05 358 2
原创 JS重难点:异步进阶
///关于async和awaitfunction loadImg(src) { const promise = new Promise(function (resolve, reject) { const img = document.createElement('img'); img.src = src; img.onload = function () { resolve(img); } i
2021-06-16 22:07:59 58
原创 JS重难点:Promise的基本使用
const LoadIMG = (src) => { const p = new Promise( (resolve, reject) => { const img = document.createElement("img"); img.src = src; img.onload = () => { resolve(img); }
2021-06-13 18:27:23 89
原创 JS重难点:关于闭包的使用场景
闭包作用域应用的特殊情况有两种表现:函数作为参数被传递函数作为返回值被返回//函数作为返回值function create(){ let a1 = 100; return function(){ console.log(a1); }}let fn1 = create();a1 = 200;fn1();//函数作为参数function print(fn){ let a = 200; fn2();}let a2 = 100;
2021-06-07 21:10:35 89
原创 JS重难点:原型链示意图
// 父类class People { constructor(name) { this.name = name } eat() { console.log(`${this.name} eat something`) }}// 子类class Student extends People { constructor(name, number) { super(name) this.number.
2021-06-07 17:13:50 91
原创 JS重难点:手写深拷贝
JS手写深拷贝/** * 深拷贝 */const obj1 = { age: 20, name: 'xxx', address: { city: 'beijing' }, arr: ['a', 'b', 'c']}const obj2 = deepClone(obj1)obj2.address.city = 'shanghai'obj2.arr[0] = 'a1'console.log(obj1.address.city)con
2021-06-07 12:14:13 121
原创 2021-06-04关于css的重要知识点
如何理解HTML语义化?让人更容易读懂(增加代码的可读性)让搜索引擎更容易读懂(SEO)块状元素和内联元素display: block/table; 有div h1 table ul ol p等等display: inline/inline-block; 有span img input button等等盒模型宽度计算offsetwidth = (内容宽度+内边距+边框),无外边距box-sizing:border-box;border-box就是用元素内容和padding和bord
2021-06-04 22:44:10 71
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人