Skip to main content

91 posts tagged with "全栈开发"

View All Tags
· 3 min read

this 指向在函数定义时不确定,调用时才确定。

  1. 全局环境:浏览器 this === window,Node 中 this === global,严格模式为 undefined
  2. 对象方法obj.method() 中 this 指向点号左侧的对象
  3. 独立调用:函数脱离对象后丢失绑定,this 回退到全局(严格模式 undefined)
  4. 箭头函数:没有独立的 this,捕获定义时所在作用域的 this
  5. 显式绑定call/apply/bind 可手动指定任意 this

核心原则:只看如何调用,不看在哪定义。

· 4 min read

package.json 里的版本号不是装饰——它决定下游装你的包时会拿到什么。

  1. SemVer 三段式:major.minor.patch,递增规则:破坏性变更 / 新功能 / bugfix
  2. 范围符号核心4 个最常用 —— ^ ~ * >=
  3. 0.x.x 陷阱^0.6.6 实际只升 patch,不升 minor
  4. 5 种依赖类型:dependencies / devDeps / peerDeps / optionalDeps / bundledDeps
  5. peerDeps 行为变化:npm 7+ 默认自动安装(npm 3-6 还会警告)
  6. 现代替代overrides(npm)/ resolutions(Yarn)取代 bundledDeps
· 5 min read

npm 发包的核心流程 10 年没变,但 撤销规则版本工具 换了 3 轮。

  • 登录:npm login + 2FA OTP(2023 年起强制)
  • files:package.json 白名单 + .npmignore 兜底
  • 版本号:npm version 自动 bump,禁手改
  • 撤销:24h 后禁止 unpublish
  • 废弃:npm deprecate 比 unpublish 安全
  • 工具:changesets 取代 standard-version