上一页 1 2 3 4 5 6 ··· 41 下一页
摘要: // 实现 instanceof 操作符 function myInstanceof(left, right) { // 实现 if(typeof right!=='function' || right.constructor null){ throw new Error('right must b 阅读全文
posted @ 2025-12-29 14:24 howhy 阅读(13) 评论(0) 推荐(0)
摘要: class Singleton { // 1. 使用私有静态属性 static #instance = null; // 2. 防止直接 new constructor() { if (Singleton.#instance) { throw new Error('Use getInstance() 阅读全文
posted @ 2025-12-29 14:06 howhy 阅读(42) 评论(0) 推荐(0)
摘要: // 实现多种数组去重方法 const arr = [1, 2, 2, 3, 4, 4, 5, 'a', 'a', 'b']; // 方法1:使用 Set console.log([...new Set(arr)]) // 方法2:使用 filter + indexOf let newArr=arr 阅读全文
posted @ 2025-12-26 16:31 howhy 阅读(28) 评论(0) 推荐(0)
摘要: function Animal(name) { this.name = name; } Animal.prototype.speak = function() { console.log(this.name + ' makes a noise'); }; function Dog(name, bre 阅读全文
posted @ 2025-12-26 15:28 howhy 阅读(21) 评论(0) 推荐(0)
摘要: function myNew(constructor,...args){ if(typeof constructor!=='function'){ return new TypeError('constructor must be a function'); } const newObj=Objec 阅读全文
posted @ 2025-12-25 15:48 howhy 阅读(17) 评论(0) 推荐(0)
摘要: function deepCopy(obj){ if(obj null || obj undefined || typeof obj!=='object'){ return obj; } if(Array.isArray(obj)){ return obj.map(item=>deepCopy(it 阅读全文
posted @ 2025-12-25 15:25 howhy 阅读(31) 评论(0) 推荐(0)
摘要: 1、如果类型相同,无须转换 2、如果其中一个操作值是null或undefined,,则另一个操作值必须是null或undefined才会返回true,否则返回false 3、如果其中一个操作值是Symbol 则返回false 4、如果操作值为string或number,则将string转为numbe 阅读全文
posted @ 2025-12-25 13:31 howhy 阅读(32) 评论(0) 推荐(0)
摘要: function getType(obj){ const type=typeof obj; console.log(type); if(type!=='object'){ return type; } return Object.prototype.toString.call(obj).replac 阅读全文
posted @ 2025-12-25 11:18 howhy 阅读(28) 评论(0) 推荐(0)
摘要: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document< 阅读全文
posted @ 2025-12-23 14:54 howhy 阅读(37) 评论(0) 推荐(0)
摘要: function uniqueArray(arr){ var result=[]; for(var i=0;i<arr.length;i++){ let flag=false; for(var j=0;j<result.length;j++){ if(deepEqual(arr[i],result[ 阅读全文
posted @ 2025-12-23 11:11 howhy 阅读(9) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 41 下一页