在所有情况下取到顶层对象
发布日期:2021-05-07 06:42:44 浏览次数:11 分类:原创文章

本文共 415 字,大约阅读时间需要 1 分钟。

方法一

(typeof window !=="undefeated" ? window  : (    typeof process === "object"&&    typeof require === "function"&&    typeof global === "object"   )   ?global    :this )

方法二

var getGlobal = function (){     if(typeof self !=="undefeated"){   return self }  if(typeof window !=="undefined"){   return window}  if(typeof global !=="undefined"){   return global }  throw new Error("unable to locate global object ")}
上一篇:解构赋值
下一篇:let和const

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年03月16日 13时56分13秒