摘要: bind、apply、call 的区别及内在实现 核心区别 方法 调用方式 参数传递 立即执行 返回值 call 直接调用 参数列表 是 函数执行结果 apply 直接调用 参数数组 是 函数执行结果 bind 返回新函数 参数列表 否 绑定this的新函数 详细解析 1. call 方法 func 阅读全文
posted @ 2025-10-11 17:27 阿木隆1237 阅读(22) 评论(0) 推荐(0)
摘要: function myNew(constructor, ...args) { ​ const obj = Object.create(constructor.prototype); // 创建一个新对象并链接到构造函数的原型​ const result = constructor.apply(obj 阅读全文
posted @ 2025-10-11 17:01 阿木隆1237 阅读(4) 评论(0) 推荐(0)
摘要: function MyPromise(executor) {​ // 初始化Promise的状态和结果 ​ this._state = 'pending'; ​ this._value = undefined;​​ // 回调函数数组,用于存储成功和失败回调 ​ this._callbacks = 阅读全文
posted @ 2025-10-11 16:58 阿木隆1237 阅读(6) 评论(0) 推荐(0)
摘要: function Animal(name) { ​ this.name = name; ​} ​​Animal.prototype.speak = function() { ​ console.log(this.name + ' makes a sound');​ };​​ function Dog 阅读全文
posted @ 2025-10-11 16:44 阿木隆1237 阅读(5) 评论(0) 推荐(0)
摘要: 在 JavaScript 中,内存泄漏通常发生在不需要的内存没有被垃圾回收器释放时。以下是常见的几种情况: 1. 意外的全局变量 // 意外的全局变量 function foo() { bar = "这是一个全局变量"; // 没有使用 var/let/const } function baz() 阅读全文
posted @ 2025-10-11 14:53 阿木隆1237 阅读(14) 评论(0) 推荐(0)
摘要: 好的,这是一个关于 JavaScript 模块化规范的全面解析。这些规范的出现都是为了解决 JavaScript 在大型项目中代码组织、依赖管理和作用域隔离的问题。 下面我将详细解释 CommonJS、AMD、CMD、UMD 和 ESM,并说明它们之间的关系和区别。 1. CommonJS - 同步 阅读全文
posted @ 2025-10-11 13:53 阿木隆1237 阅读(52) 评论(0) 推荐(0)
摘要: typeof 操作符: 可以用来确定一个值的基本数据类型,返回一个表示数据类型的字符串。 typeof 42; // "number"​ typeof "Hello"; // "string"​ typeof true; // "boolean"​ typeof undefined; // "und 阅读全文
posted @ 2025-10-11 13:47 阿木隆1237 阅读(7) 评论(0) 推荐(0)
摘要: JavaScript是浏览器的脚本语言。其最终操作都会提现到渲染线程中,也就是浏览器页面显示。如果设计成多线程的话,势必会在dom操作时出现竞争问题,这会导致渲染显示出现难以预期的问题。 阅读全文
posted @ 2025-10-11 13:41 阿木隆1237 阅读(7) 评论(0) 推荐(0)
摘要: if (a == 1 && a == 2 && a == 3) { ​ console.log('Hello World!');​ }​​ const a = { ​ i: 1, ​valueOf: function () {​ return this.i++; }​ }​ if (a == 1 & 阅读全文
posted @ 2025-10-11 13:33 阿木隆1237 阅读(4) 评论(0) 推荐(0)