[Javascript] Get Global This

const getGlobalThis = () => {
  if (typeof self !== 'undefined') return self
  if (typeof window !== 'undefined') return window
  if (typeof global !== 'undefined') return global
  if (typeof this !== 'undefined') return this
  throw new Error('Unable to locate global object')
}

 

 

posted @ 2022-03-14 15:16  Zhentiw  阅读(35)  评论(0编辑  收藏  举报