Fork me on github
摘要: function change(obj) { with(obj) { color = 'red' } } var box = { size: '15*15' } change(box); console.log(color);//red with 代码块内部,每个变量首先会指向 obj 对象属性,所 阅读全文
posted @ 2023-06-14 22:22 zjy4fun 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 下面代码的输出结果: var obj = { brand: 'apple', price: 5999 } Object.defineProperty(obj, 'id', {value: 1}) Object.defineProperty(obj, 'price', {configurable: f 阅读全文
posted @ 2023-06-14 22:13 zjy4fun 阅读(6) 评论(0) 推荐(0) 编辑
摘要: var test = 1.2 console.log(typeof test 'float');// false console.log(typeof test) // number var test2 = '4399' - 0 console.log(typeof test2 'number') 阅读全文
posted @ 2023-06-14 21:55 zjy4fun 阅读(7) 评论(0) 推荐(0) 编辑
摘要: /** * && 运算,如果前面值为true,则结果为后面的值。如果前面值为false,则值为前值. * || 运算,如果前面值为true,则结果为前面的值,如果前面的值为false,则结果为后面的值。 */ console.log(1&&2);//2 console.log(2&&1);//1 c 阅读全文
posted @ 2023-06-14 21:46 zjy4fun 阅读(68) 评论(0) 推荐(0) 编辑
摘要: 在 JavaScript 中,每个对象都有一个原型(prototype)属性,它指向另一个对象。 对象可以继承其原型对象的属性和方法。原型是 JavaScript 实现对象继承的基础概念之一,而原型链则是一种通过多层级原型连接起来的机制。 每个 JavaScript 对象(除了 null 和 und 阅读全文
posted @ 2023-06-14 21:25 zjy4fun 阅读(16) 评论(0) 推荐(0) 编辑
摘要: Function() 构造函数创建了一个新的 Function 对象,直接调用构造函数可以动态创建函数,与eval(可能访问到本地作用域)不同的是, Function 构造函数只创建全局执行的函数。 const sum = new Function('a', 'b', 'return a + b') 阅读全文
posted @ 2023-06-14 21:00 zjy4fun 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 答案是 n1 n2 p1 p2 原因:node中的微任务包含两部分: 1. process.nextTick() 注册的回调 ( nextTick task queue ) 2. promise.then() 注册的回调 ( promise task queue) node在执行微任务时,会优先执行 阅读全文
posted @ 2023-06-14 20:49 zjy4fun 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 作用域链 上面代码的输出是 GoodbyeJack ,因为执行到语句 typeof name 'undefined' 的时候,函数会从内向外(作用域链)寻找该变量,从 语句 var name; 找到该变量的定义,该变量此时的值为 undefined。自执行函数解析和执行一起完成,自己有的不会再向上查 阅读全文
posted @ 2023-06-14 20:43 zjy4fun 阅读(6) 评论(0) 推荐(0) 编辑